set,map用于统计输出

读入整数,数量不定,当输入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;}


你可能感兴趣的:(set,map用于统计输出)