1071 speech pattern

#include <string>
#include <sstream>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int main(){
    vector<string> v;
    string tmp,t;
    getline(cin,tmp);
    stringstream ss(tmp);
    while(ss >> t){
        v.push_back(t);
    }
    int max(0);
    string ret;
    map<string,int> p;
    for(int i = 0;i < v.size();i++){
        string tmp;
        for(int j = 0;j < v[i].size();j++){
            if(v[i][j] >= '0' && v[i][j] <= '9') tmp += v[i][j];
            else if(v[i][j] >= 'a' && v[i][j] <= 'z') tmp += v[i][j];
            else if(v[i][j] >= 'A' && v[i][j] <= 'Z') tmp += v[i][j] - 'A' + 'a';
            else{
                if(!tmp.empty()){
                    p[tmp]++;
                    if(p[tmp] > max){
                        max = p[tmp];
                        ret = tmp;
                    }
                    tmp.clear();
                }
            }
        }
        if(!tmp.empty()){
            p[tmp]++;
            if(p[tmp] > max){
                max = p[tmp];
                ret = tmp;
            }
            tmp.clear();
        }
    }
    printf("%s %d
",ret.c_str(),max);
    return 0;
}
原文地址:https://www.cnblogs.com/Aldorado/p/5255469.html