1. 程式人生 > >ytu 1937:查詢最大元素

ytu 1937:查詢最大元素

查詢最大元素

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 51  Solved: 23
[Submit][Status][Web Board]

Description

對於輸入的每個字串,查詢其中的最大字母,在該字母后面插入字串“(max)”。

Input

輸入資料包括多個測試例項,每個例項由一行長度不超過100的字串組成,字串僅由大小寫字母構成。

Output

對於每個測試例項輸出一行字串,輸出的結果是插入字串“(max)”後的結果,如果存在多個最大的字母,就在每一個最大字母后面都插入" (max)"。

Sample Input

abcdefgfedcba
xxxxx

Sample Output

abcdefg(max)fedcba x(max)x(max)x(max)x(max)x(max)

HINT

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char s[101];
 8     while(cin.getline(s,100,'\n')){
 9         char maxx='\000';
10         for(int i=0;s[i]!='\0';i++){
11             if(s[i]>maxx)
12 maxx=s[i]; 13 } 14 for(int i=0;s[i]!='\0';i++){ 15 cout<<s[i]; 16 if(s[i]==maxx){ 17 cout<<"(max)"; 18 } 19 } 20 cout<<endl; 21 } 22 return 0; 23 }