Hangzhou Electric Oj brush title (2025)

Find the largest element

Subject description:

For each input string, wherein the alphabet to find the maximum, inserts the string "(max)" following that letter.

Input

The input data includes a plurality of test instances, each string of one line of a length not exceeding 100 composition string composed only of uppercase and lowercase letters.

Output

An output line for each test case string, the result is the output result of the insertion string "(max)", if a plurality of maximum letters exist, each letter is inserted behind the maximum "(max)".

Sample Input

abcdefgfedcba 
xxxxx

Sample Output

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

By the answer:

#include <stdio.h>
int main()
{
	char str[100];
	int i,max,k;
	while(scanf("%s",&str)!=EOF){            // %s:输入一串字符 
		max=0;
	    k=0;
	    for(i=0;str[i]!='\0';i++){
		    if(str[i]>max){
			    max=str[i];
			    k=i;
		    }
	    }
	    for(i=0;str[i]!='\0';i++){
		    if(str[i]==str[k])
			    printf("%c(max)",str[i]);          //在最大元素后面加(max)
		    else
			    printf("%c",str[i]);	
	    }
		printf("\n");
	}
	return 0;
}

 

Published 55 original articles · won praise 0 · Views 1014

Guess you like

Origin blog.csdn.net/ZhangShaoYan111/article/details/104138461