点击打开链接
题目描述:
对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
题解:
日常写水题,,,
#include<iostream> #include<cstring> using namespace std; int main() { char a[105]; while(cin>>a) { int i; char t=0; for(i=1;i<strlen(a);i++) { if(a[i]>a[t]) t=i; } if(t==0) { cout<<a[0]<<"(max)"; for(i=1;i<strlen(a);i++) { if(a[i]==a[t]) cout<<a[i]<<"(max)"; else cout<<a[i]; } cout<<endl; } else { for(i=0;i<t;i++) cout<<a[i]; cout<<a[t]<<"(max)"; for(i=t+1;i<strlen(a);i++) { if(a[i]==a[t]) cout<<a[i]<<"(max)"; else cout<<a[i]; } cout<<endl; } } return 0; }
