https://pintia.cn/problem-sets/994805260223102976/problems/994805280817135616
一直不断输入字符的方法要记住了,还有ascii码转字符,直接用char强制转换就行。
#include<iostream>
#include<cctype>
using namespace std;
int main() {
char ch;
int m, max_index=0, time[128]={0};
while(cin.peek()!='\n') //cin.peek()相当于偷看一眼再放回流中
{
cin >> ch;
if(isupper(ch)){
ch += 32;
}
m = ch;
time[m] ++;
if(time[m] > time[max_index] && isalpha(ch)){
max_index = m;
}else if(time[m] == time[max_index] && isalpha(ch)){
max_index = m < max_index ? m : max_index;
}
}
cout << (char)max_index << " " << time[max_index];
}