对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串"(max)"。

/*
对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串"(max)"。
样例输入
abcdefgfedcba
xxxxx
样例输出
abcdefg(max)fedcba
x(max)x(max)x(max)x(max)x(max)
*/
#include <stdio.h>
#include<string.h>
int main()
{
    int i;
    char str[100],maxch;
    gets(str);
    maxch=str[0];
    for(i=0;str[i]!='\0';i++){
        if(str[i]>maxch){
            maxch=str[i];
        }
    }
    for(i=0;str[i]!='\0';i++){
        printf("%c",str[i]);
        if(str[i]==maxch){
            printf("(max)");
        }
    }
    printf("\n");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zhaohuan1996/p/11849037.html
今日推荐