2016 Ali School recruit Research and development algorithm problem 9.9

Source: Internet
Author: User

Main topic:

Enter a string stream with numbers and non-numbers, non-digits separated by numbers, to find out the number that has the most occurrences.

Ideas:

First replace all non-digits with a uniform character, and then find the number, you need to determine whether the next character is a number, and then save the number into the HashMap, the presence of the number, HashMap the value+1, and the last output value of the largest number.

Code:

1#include"iostream"2#include"Map"3#include"Vector"4#include"algorithm"5 #defineMAX 100006 using namespacestd;7 8 CharC[max];9 BOOLtag;Tenmap<int,int>M,msort; One  A intMain () - { -      while(Cin >>c) the     { -Tag =false; -          for(inti =0; I < strlen (c); i++) -         { +             if(C[i] <'0'|| C[i]>'9') -C[i] ='*'; +cout <<C[i]; A         } atcout <<Endl; -          for(inti =0, j=0; I < strlen (c); i++) -         { -             intt=0; -              while(C[i] = ='*') -i++; in              while(C[i]! ='*'&&c[i]!=' /') -             { toTag =true; +T + = C[i]-'0'; -  the                 if(C[i +1] ==' /') *                      Break; $ Panax Notoginseng                 if(C[i +1] =='*') -Tag =false; the  +                 if(TAG) AT *=Ten; thei++; +             }  -             if(M.count (t)) $             { $m[t]++; -}Else                 -M[T] =1; the  -J + +;Wuyi         } the  -map<int,int>::iterator res =M.begin (); Wu          for(map<int,int>::iterator iter = M.begin (); Iter!=m.end (); iter++) -         { About             if(Iter->second > res->second) $res =iter; -  -         } -cout << Res->first <<Endl; A  + m.clear (); the     } -System"Pause"); $  the}

2016 Ali School recruit Research and development algorithm problem 9.9

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.