C/C++练习第三贴
#include <iostream>using namespace std;
#include <stack>
void test01()
{
stack<int>s;
for (int i = 0; i < 10; i++)
{
s.push(i);
}
while (!s.empty())
{
cout << "栈顶元素:"<<s.top()<<endl;
s.pop();
}
cout <<"栈的大小为"<< s.size() << endl;
}
int main()
{
test01();
return 0;
} 楼主加油 楼主加油
怎么调用啊 #include <iostream>
#include <set>
using namespace std;
#if 0
void test01()
{
set<int>s;
s.insert(20);
s.insert(40);
s.insert(30);
s.insert(50);
s.insert(10);
s.insert(60);
pair<set<int>::iterator, bool>ret =s.insert(80);
if (ret.second)
{
cout << "第一次插入成功" << endl;
}
else
{
cout <<"第一次插入失败" <<endl;
}
ret = s.insert(80);
if (ret.second)
{
cout << "第er次插入成功" << endl;
}
else
{
cout << "第er次插入失败" << endl;
}
multiset<int>ms;
ms.insert(20);
ms.insert(20);
ms.insert(20);
ms.insert(20);
for (multiset<int>::iterator it=ms.begin();it!=ms.end();it++)
{
cout << *it << " ";
}
cout << endl;
}
#endif
//pair对组
void test02()
{
pair<string, int>p("汤姆",20);
cout << "姓名" << p.first << "年龄" << p.second << endl;
pair<string, int>p2 = make_pair("jerry", 30);
cout << "姓名" << p2.first << "年龄" << p2.second << endl;
}
int main()
{
test02();
return 0;
} #include <iostream>
#include <map>
using namespace std;
void printmap(map<int, int>& m)
{
for (map<int,int>::iterator it=m.begin();it!=m.end();it++)
{
cout << "KEY=" << it->first << "Value="<<(*it).second<<endl;
}
cout << endl;
}
void test01()
{
map<int, int>m;
m = 10;
m.insert(make_pair(1, 20));
m.insert(pair<int, int>(2, 30));
m.insert(make_pair(3, 61));
m.insert(make_pair(4, 22));
m.insert(make_pair(5, 23));
printmap(m);
}
int mian()
{
test01();
return 0;
} #include <iostream>
#include<map>
#include <vector>
using namespace std;
#define chehua 0
#define meishu 1
#define yanfa 2
class worker
{
public:
string m_name;
int m_salary;
};
void createworker(vector<worker>&v)
{
string nameseed = "ABCDEFGHIJ";
for (int i = 0; i < 10; i++)
{
worker wok;
wok.m_name = "员工";
wok.m_name += nameseed;
wok.m_salary = rand() % 10000 + 10000;
v.push_back(wok);
}
}
void test01(vector<worker>&v)
{
for (vector<worker>::iterator it = v.begin(); it != v.end(); it++)
{
cout << "员工姓名:" << it->m_name << "员工工资:" << it->m_salary << endl;
}
cout << endl;
}
void setgroup(vector<worker>&v,multimap<int ,worker>&m)
{
for (vector<worker>::iterator it = v.begin(); it != v.end(); it++)
{
int deptid = rand() % 3;
m.insert(make_pair(deptid, *it));
}
}
void showworkbygourp(multimap<int,worker>&m)
{
cout<<"策划部门信息:"<<endl;
multimap<int,worker>::iterator pos= m.find(chehua);
int count = m.count(chehua);//统计具体人数
int index = 0;
for (;pos != m.end()&&index<count; pos++,index++)
{
cout<<"姓名:"<<pos->second.m_name<<"工资为:"<<pos->second.m_salary<<endl;
}
cout<<"------------------------"<<endl;
cout << "美术部门信息:" << endl;
pos = m.find(meishu);
count = m.count(meishu);//统计具体人数
index = 0;
for (; pos != m.end() && index < count; pos++, index++)
{
cout << "姓名:" << pos->second.m_name << "工资为:" << pos->second.m_salary << endl;
}
cout << "------------------------" << endl;
cout << "研发部门信息:" << endl;
pos = m.find(yanfa);
count = m.count(yanfa);//统计具体人数
index = 0;
for (; pos != m.end() && index < count; pos++, index++)
{
cout << "姓名:" << pos->second.m_name << "工资为:" << pos->second.m_salary << endl;
}
}
int main()
{
vector<worker>vworker;
createworker(vworker);
test01(vworker);
multimap<int, worker>mworker;
setgroup(vworker,mworker);
showworkbygourp(mworker);
return 0;
} #include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
using namespace std;
class compare
{
public:
bool operator()(int v1, int v2)
{
return v1 > v2;
}
};
void test01()
{
plus<int>p;
cout<<p(10,10)<<endl;
negate<int>n;
cout << n(10) << endl;
}
void test02()
{
vector<int>v;
v.push_back(20);
v.push_back(10);
v.push_back(40);
v.push_back(30);
v.push_back(60);
v.push_back(50);
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << *it << " ";
}
cout << endl;
sort(v.begin(),v.end(),greater<int>());
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
int main()
{
test01();
test02();
return 0;
} #include <iostream>
#include <graphics.h>
using namespace std;
#define wide 800
#define height 600
int main()
{
initgraph(wide, height);
SetWindowTextA(GetHWnd(), "贪玩蓝月");
setbkcolor(LIGHTBLUE);
cleardevice();//清屏
//fillcircle(300, 250, 50);
setfillcolor(RGB(100, 100, 100));//设置填充颜色
fillrectangle(200, 50, 500, 100);
settextcolor(RGB(0,255,0));//设置文字颜色
settextstyle(50,0,"微软雅黑");//文字大小 间隔 字体
setbkmode(TRANSPARENT);//文字设置透明
outtextxy(300, 250, "首充6元");
char chongzhi[] = "充值界面";
int kuang=300/2-textwidth(chongzhi)/2;//文字的宽度
int gao = 50/2-textheight(chongzhi) / 2;//文字的高度
outtextxy(kuang + 200, gao + 50, chongzhi);
getchar();
closegraph();
return 0;
}
页:
[1]
2