标签:
题是比较水的啦,但是好久没有用sort函数啦,有点生疏^...^
1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 struct shu{ 7 int num,ord; 8 }p[1005]; 9 int cmp(shu x,shu y) 10 { 11 if(x.num==y.num){ 12 return x.ord<y.ord; 13 } 14 else return x.num>y.num; 15 } 16 17 int main() 18 { 19 int n,k; 20 while(cin>>n){ 21 for(int i=1;i<=1000;i++){ 22 p[i].num=0; 23 p[i].ord=i; 24 } 25 for(int i=1;i<=n;i++){ 26 cin>>k; 27 p[k].num++; 28 29 } 30 sort(p,p+1001,cmp); 31 for(int i=0;i<=1000;i++){ 32 if(p[i].num!=0){ 33 cout<<p[i].ord<<" "<<p[i].num<<endl; 34 } 35 } 36 } 37 }
标签:
原文地址:http://www.cnblogs.com/shangjindexiaoqingnian/p/5836809.html