易懂题解(可用于改错)
2025-07-17 11:06:04
发布于:上海
9阅读
0回复
0点赞
要记得比较时当有两个字符出现次数相同时,应当取ASCLL码值较小者
#include<iostream>
using namespace std;
string s;
int sum[1001];
int maxx;
char s1;
int main(){
cin >> s;
int len = s.size();
for(int i = 0; i < len; i++){
sum[s[i]]++;
}
for(int i = 0; i < len; i++){
if(maxx < sum[s[i]]){
maxx = sum[s[i]];
s1 = s[i];
}
if(maxx == sum[s[i]] && s[i] < s1){//是否忽视了这一步?
maxx = sum[s[i]];
s1 = s[i];
}
}
cout << s1 << " " << maxx;
return 0;
}
全部评论 2
觉得作者码风看着舒服的,可以申请来此团交流学习:https://www.acgo.cn/application/1942517586006433792
2025-07-17 来自 上海
0制作不易,留赞后去
2025-07-17 来自 上海
0
有帮助,赞一个