[HDU] [2025] Find the Maximum Element

Problem Description

Loading...

Problem Analysis

Not a hard problem.
The length is mainly because that (max) output is rather troublesome.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<string.h>
int main() {
	char s[120],a[1000];
	char max;
	int i,j;
	while(scanf("%s",s)!=EOF) {
		for(max=i=0; i<strlen(s); i++) {
			if(s[i]>max)
				max=s[i];
		}
		memset(a,0,sizeof(a));
		for(i=0,j=0; i<strlen(s); i++) {
			a[j]=s[i];
			if(s[i]==max) {
				j++;
				a[j]='(';
				j++;
				a[j]='m';
				j++;
				a[j]='a';
				j++;
				a[j]='x';
				j++;
				a[j]=')';
			}
			j++;
		}
		printf("%s\n",a);
	}
	return 0;
}

It’s probably better to start directly from the output part.

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...