* HDoj 2025 to find the largest element

Problem 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)
 

 

Author
lcy
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2027  2026  2031  2032  2033 
 
This 题 Note
1 regardless of capitalization, relatively simple code ASIIC
2 Note codeblocks breakpoint debugging, if the project path contains Chinese, will not stop at the breakpoint is encountered, so if the project path in English.
3 string stored in the array definition, the best use  void * Memset ( void * STR , int C , size_t n- ) at initialization, to prevent '\ 0' terminator string as the inside unassigned, misjudged string length, (i.e., preferably not initialized to '\ 0' is ASIIC code)
 
C language code as follows:
#include<stdio.h>
#include<string.h>
int main()
{
    char s[300];
    memset(s,123,300);
    while(scanf("%s",s)!=EOF)
    {
        getchar();
        char temp='A';
        for(int i=0;s[i]!='\0';i++)
            if(s[i]>temp)
                temp=s[i];

        for(int i=0;s[i]!='\0';i++)
        {
            if(s[i]==temp)
            {
                for(int j=strlen(s);j>=i+1;j--)
                    s[j+5]=s[j];
                s[++i]='(';
                s[++i]='m';
                s[++i]='a';
                s[++i]='x';
                s[++i]=')';
            }
        }
        printf("%s\n",s);
    }
}

 

Guess you like

Origin www.cnblogs.com/wzmm/p/12581940.html