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;
}
上一篇: JS中Array.prototype.fill()
下一篇: yaf namespace的使用