在这儿出现了问题:次数相同的话,如果有并列,则输出按字母序最小的那个字母,这儿的解决方法很巧妙!
#include
<bits
/stdc
++.h
>
using namespace std
;
int hashtable
[300]={0};
int main(){
string s
;
getline(cin
,s
);
for(int i
=0;i
<s
.length();i
++){
if(isalpha(s
[i
]))hashtable
[tolower(s
[i
])]++;
}
int max
=-1;
char c
;
for(int i
='a';i
<'z';i
++){
if(hashtable
[i
]>max
){
max
=hashtable
[i
];
c
=i
;
}
}
cout
<<c
<<" "<<max
;
return 0;
}
转载请注明原文地址: https://mac.8miu.com/read-496976.html