题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2025
题解:
先找到最大的元素。在输出时,遍历到最大元素时,只需在其后追加输出(max)即可
AC代码:
#include <string>
#include <iostream>
using namespace std;
int main() {
string str;
while (cin >> str) {
char c = 'a';
for(int i = 0; i < str.size(); i++) {
if(str[i] > c) c = str[i];
}
for(int i = 0; i < str.size(); i++) {
if(str[i] == c) {
cout << str[i] << "(max)";
}
else {
cout << str[i];
}
}
cout << endl;
}
return 0;
}