cppAcademy
FROM LEARNING TO COMPETING

Beginner.
Your first challenges.

Bulgarian Informatics Group E · 2007–2026

270 independently explained problems: 54 Municipal, 54 Regional, 105 National Olympiad tasks and 57 Autumn Tournament tasks. Start with the easier tasks and work upwards. Difficulty labels are learning estimates, not official ratings; Group E also includes challenging national-level problems. Years follow Arena’s competition-season labels. Source clarifications are noted on affected tasks.
GROUP E2025 · EasyRunning maximum

Tallest Basketball Friend

National Olympiad — Municipal round (2025 season)

Submission name: bbp.cpp

Problem summary

Five friends give their uppercase initial and height. Print the initial of the tallest; when heights tie, choose the one read last.

Input

Five lines, each with an uppercase Latin letter and a height.

Output

The winning friend’s initial.

Constraints

Exactly five friends; heights are between 100 and 250 centimeters.

Worked example

An independently prepared example for this explanation.

Input

Z 152
H 188
W 165
E 188
H 175

Output

E

Solution analysis

  1. Keep the largest height seen and the corresponding initial. Read each friend once.
  2. Replace the current winner when the new height is greater than or equal to the best. Equality is essential because the later friend wins ties.
  3. In the sample H first sets the record of 188, but E later matches 188 and replaces H. The final friend is shorter, so E remains the answer.

Why it works

After each input line the stored friend is the last tallest among all processed friends: a shorter height cannot change it, while an equal or larger height makes the new friend the required winner. After five lines this is the desired result.

Complexity: O(1) time and O(1) extra space for five friends.

Watch out. Use >= rather than > when updating the maximum.

Commented C++17 solution

An independently written complete program with standard headers.

#include <iostream>
using namespace std;
int main() {
    int bestHeight = -1;
    char winner = 'A';
    for (int i = 0; i < 5; i++) {
        char initial;
        int height;
        cin >> initial >> height;
        // Equality replaces the winner so that the last tied friend wins.
        if (height >= bestHeight) {
            bestHeight = height;
            winner = initial;
        }
    }
    cout << winner << '\n';
}

Source: Arena Olimpiici ↗