#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char str[1100]={0};
int temp[200]={0};
int temp1[200]={0};
bool cmp(int a,int b)
{
return a<b;
}
int main()
{
cin.getline(str,1100);
int max=0;
int j=0;
for(int i=0;i<strlen(str);i++)//将大写字母全部变成小写字母
{
if(str[i]>='A'&&str[i]<='Z')
{
str[i]=str[i]-'A'+'a';
}
}
for(int i=0;i<strlen(str);i++)
{
int a=str[i];
if(a<'a'||a>'z') continue;
temp[a]++;
if(temp[a]>max)
{
j=0;
max=temp[a];
temp1[0]=a;
j++;
}
else if (temp[a]==max)
{
temp1[j++]=a;
}
}
sort(&temp1[0],&temp1[j],cmp);
printf("%c ",temp1[0]);
cout<<max;
}
PAT 自学题解 B1042
最新推荐文章于 2024-07-25 23:22:43 发布