[] Find the largest element acm2025

*** problems:
Problem the Description
for each input string, wherein the alphabet to find the maximum, inserts the string "(max)" following that letter.

Input
Input data comprises 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
Output line string for each test case, the output result is the result of inserting the 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)***

Code:

#include<iostream>
#include<cstring>

using namespace std;
int main() {
	char s[101];
	while(gets(s)) {
	
		
		char max=s[0];
		
		for(int i=0; i<strlen(s); i++) {
			if(s[i]>max){
				max=s[i];
			}
			}
			for(int j=0;j<strlen(s);j++){
			cout<<s[j];
			if(s[j]==max){
				cout<<"(max)";
			}
				
			}
		cout<<endl;
	}
	return 0;
}
Published 42 original articles · won praise 18 · views 394

Guess you like

Origin blog.csdn.net/weixin_42918559/article/details/104075652