1. 程式人生 > >HDU 2025 查找最大元素

HDU 2025 查找最大元素

its lse main otto esc ace xxx 一個 CA

http://acm.hdu.edu.cn/showproblem.php?pid=2025

Problem 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) 代碼:
#include <bits/stdc++.h>

using namespace std;

char s[111];
int main()
{
    while(scanf("%s",s)!=EOF)
    {
        int len = strlen(s);
        int max=s[0];
        for(int i=0; i<len; i++)
        {
            if(s[i]>=max)
                max=s[i];
        }
        for(int i=0; i<len; i++)
        {
            if(s[i]==max)
                printf("%c(max)",s[i]);
            else
                printf("%c",s[i]);
        }
        cout<<endl;
    }
    return 0;
}

  

HDU 2025 查找最大元素