//复习三种容器
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
struct S
{
string name;
double score;
bool operator==(S s)
{
return score<s.score;//返回小的数,效果是自动排序(从小到大)
}
};
class test
{
private:
vector<S>a1;
vector<S>::iterator p1;
list<S>a2;
list<S>::iterator p2;
map<int,S>a3;
map<int,S>::iterator p3;
public:
test()
{
S t;//结构体
t.name="111";t.score=11;
a1.push_back(t);a2.push_back(t);
a3.insert(pair<int,S>(1,t));//第一个是数据类型,第二个是结构体,括号内的是插入的数据
t.name="222";t.score=22;
a1.push_back(t);a2.push_back(t);
a3.insert(pair<int,S>(2,t));
t.name="333";t.score=33;
a1.push_back(t);a2.push_back(t);
a3.insert(pair<int,S>(3,t));
t.name="444";t.score=44;
a1.push_back(t);a2.push_back(t);
a3.insert(pair<int,S>(4,t));
t.name="555";t.score=55;
a1.push_back(t);a2.push_back(t);
a3.insert(pair<int,S>(5,t));
//
}
void Find1(double d)
{
S temp;
temp.score=d;
p1=a1.begin();
while(true)
{
p1=find(p1,a1.end(),temp);//第一个参数是p的起始地址,第二个参数是p的结束地址,第三个参数是需要查找的值
if(p1!=a1.end())
{
cout<<p1->name<<"-"<<p1->score<<endl;
++p1;
}
else break;
}
}
void Find2(double d)
{
S temp;
temp.score=d;
p2=a2.begin();
while(true)
{
p2=find(p2,a2.end(),temp);
if(p2!=a2.end())
{
cout<<p2->name<<"-"<<p2->score<<endl;
++p2;
}
else break;
}
}
void Find3(int m)
{
p3=a3.find(m);
if(p3!=a3.end())
{
cout<<p3->first<<"-"<<p3->second.name
<<"-"<<p3->second.score<<endl;
}
else cout<<"no person!"<<endl;
}
};
int main()
{
test t;
t.Find3(6);
return 0;
}
//gotoxy函数
#include <windows.h>
#include <iostream>
using namespace std;
//光标移动到指定坐标处
void gotoxy(int x,int y)
{
HANDLE h;//句柄,对象的索引
COORD c;//结构体,坐标值
c.X=x;
c.Y=y;
h=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h,c);
}
int main()
{
gotoxy(5,5);
cout<<"hello!";
return 0;
}
gotoxy(x, y) 将光标移动到指定列坐标 x 和行坐标 y。设置光标到文本屏幕的指定位置,其中参数 x,y 为文本屏幕的坐标。gotoxy(0,0)将光标移动到屏幕左上角。
//光标移动到指定坐标处
void gotoxy(int x,int y)
{
HANDLE h;