【PAT甲级】1071. Speech Patterns (25)

来源:互联网 发布:人工智能等级 编辑:程序博客网 时间:2024/06/06 12:52
#include <iostream>#include <string>#include <map>#include <cctype>using namespace std;int main() {    string s, tmp;    map<string, int> m;    getline(cin, s);    for (int i = 0; i < s.length(); i++) {        if (isalnum(s[i])) {            s[i] = tolower(s[i]);//assignment            tmp += s[i];        } else {            if (tmp.length())                m[tmp]++;            tmp = "";        }    }    if (tmp.length()) m[tmp]++;    string ms;    int max = 0;    for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it) {        if (it->second > max) {            max = it->second;            ms = it->first;        }    }    cout << ms << " " << max << endl;    return 0;}
原创粉丝点击