Test instructions: Each row gives a name and an int value, and the name can be repeated. Required for the same personal name statistics int value, the largest first output, if the same, then according to the number of person names appear, if the same, then the name of the dictionary sequence.
Train of thought: After entering all sorts, write a comparison function to pass in the sort.
1#include <bits/stdc++.h>2 using namespacestd;3 4 structnode5 {6 Charnam[ A];7 intlik;8 intTim;9}a[5500];Ten Onemap<string,int> mapp2;//Name Mapping to int is better handled A - intCMP (node Ll,node RR) - { the if(ll.lik<Rr.lik) - return 0; - Else if(ll.lik>Rr.lik) - return 1; + - if(ll.tim<Rr.tim) + return 0; A Else if(ll.tim>Rr.tim) at return 1; - - - if(strcmp (Ll.nam, Rr.nam) >0) - return 0; - Else return 1; in } - to intMain () + { - //freopen ("Input.txt", "R", stdin); the * //Sort by probability, sort by time, and then order by dictionary. $ Panax Notoginseng intn, like; - Chars[ A]; the stringtemp; +map<string,int>:: iterator it; A the while(cin>>N) + { -Memset (A,0,sizeof(a)); $ mapp2.clear (); $ - intk=0; - for(intI=0; i<n; i++) the { -scanf"%s%d",s,&Like );Wuyitemp=s; theit=Mapp2.find (temp); - Wu if(It==mapp2.end ())//new here. - { Aboutmapp2[temp]=K; $ -a[k].lik=Like ; -a[k].tim=1; - strcpy (A[k].nam, s); Ak++; + } the Else - { $a[it->second].lik+=Like ; thea[it->second].tim++; the } the } theSort (a,a+k,cmp); -printf"%d\n", k); in for(intI=0; i<k; i++) theprintf"%s%d%d\n", A[i].nam, A[i].lik, a[i].tim); the } About return 0; the}
AC Code
Nbut 1118 Marisa ' s affair (sort statistics, water)