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

1071 Speech Patterns (25 分)

程序员文章站 2024-02-15 17:37:47
...

/**

1、getline(cin, ans)输入

2、map遍历

   for(iter = s.begin(); iter != s.end(); iter++)

    {

if(iter->second > Max)

{

Max = iter->second;

sss = iter->first;

}

}

!!!处考虑到

input:

can can can

*/

 

#include <iostream>

#include <cstdio>

#include <cstring>

#include <vector>

#include <algorithm>

#include <map>

using namespace std;

map<string, int> s;

map<string,int>::iterator iter;

int main()

{

    string ss, sss = "", str;

    getline(cin, ss);

    ss += " ";                  ///!!!

    int Max = 0;

    for(int i = 0; i < ss.size(); i++)

    {

        ss[i] = tolower(ss[i]);                  ///变小写

        if((ss[i] >= 'a' && ss[i] <= 'z') || (ss[i] >= '0' && ss[i] <= '9'))

        {

            str += ss[i];

        }

        else

        {   if(str.size() != 0)

            {

                s[str]++;

                if(s[str] > Max)

                {

                    Max = s[str];

                    sss = str;

                }

                str.clear();



            }

        }

    }

    /*

    for(iter = s.begin(); iter != s.end(); iter++)

    {

if(iter->second > Max)

{

Max = iter->second;

sss = iter->first;

}

}*/

    cout << sss << " " << Max << endl;

    return 0;

}