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
- Keep the largest height seen and the corresponding initial. Read each friend once.
- 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.
- 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.
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';
}