HDU2025 Find the largest element

【topic】


[Thinking] Use a character array to read a string, set a max to record the largest letter, and initialize it to '\0'. Then iterate over the string, inserting (max) after the output maximum letter.

[Code] The C++ code of AC is as follows:

#include <iostream>
#include <string.h>
using namespace std;
char s[1000];
intmain()
{
    while (cin >> s)
    {
        char max = '\0';
        int len ​​= strlen(s);

        for (int i = 0;i < len;i++)
        {
            if (s[i] > max)
                max = s[i];
        }

        for (int i = 0;i < len;i++)
        {
            cout << s[i];
            if (s[i] == max)
                cout << "(max)";
        }
        cout << endl;
    }

    return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324771582&siteId=291194637