首页 > 其他 > 详细

1071 speech pattern

时间:2016-03-08 21:29:14      阅读:210      评论:0      收藏:0      [点我收藏+]
#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\n",ret.c_str(),max);
    return 0;
}

 

1071 speech pattern

原文:http://www.cnblogs.com/Aldorado/p/5255469.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!