分析:难点在结构体排序?emm...这题没有难点下一题。
1 #include <iostream> 2 #include<cstdio> 3 #include<vector> 4 #include<map> 5 #include<set> 6 #include<algorithm> 7 using namespace std; 8 struct node 9 { 10 char name[30]; 11 double ave; 12 set<int>q; 13 map<int,int>mp; 14 int sum,kind,all; 15 }no[105]; 16 bool cmp(node a,node b) 17 { 18 19 if(a.kind == b.kind) 20 { 21 return a.ave<b.ave; 22 } 23 return a.kind > b.kind; 24 } 25 int main() 26 { 27 int n,a; 28 scanf("%d",&n); 29 for(int i = 1; i <= n; i ++) 30 { 31 scanf("%s%d",no[i].name,&no[i].all); 32 for(int j = 1; j <= no[i].all; j ++) 33 { 34 scanf("%d",&a); 35 no[i].q.insert(a); 36 no[i].mp[a]++; 37 no[i].sum+=no[i].mp[a]; 38 } 39 no[i].kind=no[i].q.size(); 40 no[i].ave=no[i].sum/(double)no[i].all; 41 } 42 sort(no+1,no+n+1,cmp); 43 if(n==1)printf("%s - -",no[1].name); 44 else if(n==2)printf("%s %s -",no[1].name,no[2].name); 45 else 46 { 47 printf("%s %s %s",no[1].name,no[2].name,no[3].name); 48 } 49 return 0; 50 }