Nbut 1118 Marisa ' s affair (sort statistics, water)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.