思路:
这个题就是个普通的字符串处理的题,不要忘了大小写的处理,没有什么要特殊注意的点。
代码:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int len, i, j, max = 0;
int num[26] = { 0 };
string str;
char s;
getline(cin, str);
len = str.size();
for (i = 0; i < len; i++)
{
s = str[i];
if (s >= 'A' && s <= 'Z')
{
num[s - 'A']++;
}
else if (s >= 'a' && s <= 'z')
{
num[s - 'a']++;
}
}
for (i = 0; i < 26; i++)
if (num[i]>max)
max = num[i];
for (i = 0; i < 26;i++)
if (max == num[i])
{
s = i + 'a';
break;
}
cout << s << " " << max;
//while (1)
//{ }
return 0;
}