您的位置:首页 > 其它

set,map用于统计输出

2015-05-08 18:46 155 查看
读入整数,数量不定,当输入0结束,求出现的数及其次数:

int main(){
int a;
multiset<int>ss;
cout<<"enter"<<endl;
cin>>a;
while(a!=0){
ss.insert(a);
cin>>a;}
cout<<"the inf:"<<endl;
multiset<int>::iterator p;
for(p=ss.begin();p!=ss.end();p++)
cout<<*p<<" ";
//int *p1=new int [ss.size()];
cout<<"\n max of number"<<max<int>(ss)<<endl;
map<int,int>m1;
for(p=ss.begin();p!=ss.end();p++)
m1.insert(map<int,int>::value_type(*p,ss.count(*p)));
cout<<"the inf of all:"<<endl;
map<int,int>::iterator p1;
for(p1=m1.begin();p1!=m1.end();p1++)
cout<<p1->first<<" "<<p1->second<<endl;

system("pause");
return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: