欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

1071 Speech Patterns (25 分)(******)

程序员文章站 2024-02-16 13:04:22
...
#include <iostream>
#include <cstdio>
#include <map>
#include <sstream>
#include <string>
#include <cstring>
using namespace std;

bool wetherQ(char a)
{
    if(a <= 'z' && a >= 'a') return true;
    if(a <= 'Z' && a >= 'A') return true;
    if(a <= '9' && a >= '0') return true;
    return false;
}

int main()
{
    map<string,int>mp;
    string s;
    getline(cin,s);
    int i = 0;
    while(i<s.length())
    {
        string word;
        while(i<s.length() && wetherQ(s[i]) == true)
        {
            char ll = s[i];
            if(s[i] <= 'Z' && s[i] >= 'A')
                s[i] += 'a' - 'A';
            word += s[i++];
        }
        if(word != "")
        {
            mp[word]++;
        }
        while(i<s.length() && wetherQ(s[i]) == false)
            i++;
    }

    map<string,int>::iterator it;
    string ans1;
    int ans2  = -1;
    for(it = mp.begin();it!=mp.end();it++)
    {
        if(ans2 < it->second)
        {
            ans2 = it->second;
            ans1 = it->first;
        }
    }
    cout<<ans1<<" "<<ans2;

    return 0;
}