1175 查找最大元素
题目描述
对于输入的字符串,查找其中的AscII码最大字母,在该字母后面插入字符串"(max)”。不包括引号。
输入描述
/*
输入一行长度不超过100的字符串,字符串仅由大小写字母构成。
*/
abcdefgfedcba
输出描述
/*
输出一行字符串,输出的结果是插入字符串"(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入"(max)"。
*/
abcdefg(max)fedcba
#include<stdio.h>
#include<string.h>
void findmax(char s[]){
int i =0;
int len = strlen(s);
char maxc = s[0];
int a[101]={0};
for(i=0;i<len;i++)
if(maxc<s[i])
maxc = s[i];
for(i=0;s[i]!=' ';i++){
if(s[i]!=maxc)
printf("%c",s[i]);
else
printf("%c(max)",s[i]);
}
printf("
");
}
int main(){
char str[101];
scanf("%s",str);
findmax(str);
return 0;
}