Huawei Machine Test-word count

Source: Internet
Author: User

Enter an article to output the highest-frequency and sub-high-frequency words (all lowercase, comma delimited). There are only three separators for spaces, commas, and periods in the article.

Regardless of the frequency of the same situation. Case is ignored.


input: I am a student. I come from Xidian,i love Xidian.

Output: I,xidian


#include <iostream> #include <string> #include <map> #include <cctype>using namespace Std;int    Main (int argc, char *argv[]) {string S;    map<string,int>m;        while (Getline (cin,s)!=null) {string T; for (int i=0;i<s.size (); ++i) {if (s[i]== ' | | | s[i]== ', ' | |            s[i]== '. ')                {m[t]+=1;            T= "";        } else t+=s[i];    }} int first=0,second=0;    String s1,s2;            For (Map<string,int>::iterator It=m.begin (); It!=m.end (); ++it) {if (It->second>first) {            s1=it->first;        first=it->second;            } if (It->second>second&&it->second<first) {s2=it->first;        second=it->second;    }} for (int i=0;i<s1.size (); ++i) {cout<< (char) ToLower (S1[i]);    } cout<< ","; for (int i=0;i<s2.size (); ++i) {cout<< (char) ToLower (s2[i]);    } cout<< "\ n"; return 0;}




Huawei Machine Test-word count

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.