Middle Guy
Time limit: 0.5 s.
Memory limit: 256 MB
Three friends, \(A\), \(B\), and \(C\), of different heights, \(h_A\), \(h_B\), and \(h_C\), respectively, want to determine who is of the middle height, that is, which one of them is neither the tallest nor the shortest, so they can call him the Middle Guy.
You are given the heights of the three friends, find out which one is in the middle by height.
Input
The input consists of \(3\) integers \(h_A\), \(h_B\), and \(h_C\). \((1 \le h_A, h_B, h_C \le 10^6)\), the heights of the three friends. No two of these integers are equal.
Output
Output a single letter “A”, “B”, or “C”, the friend who is the Middle Guy.
Make sure you only print one uppercase letter in a single line, and nothing else.
Scoring
In this problem, each test case will be scored separately. Your score is the sum of scores for all test cases.
Example
Input
172 158 164
Output
C
Note
In the sample testcase, the friend A is the tallest, with the height 172, the friend B is the shortest, with the height 158, and the friend C is in between them, with the height 164. This makes the friend C be the Middle Guy.
Solution
Store each height together with its friend’s letter and sort the three pairs. The friend in the middle of the sorted order is the answer.
The complexity is \(O(1)\).
#include <algorithm>
#include <array>
#include <iostream>
using namespace std;
int main() {
array<pair<int, char>, 3> friends;
cin >> friends[0].first >> friends[1].first >> friends[2].first;
friends[0].second = 'A';
friends[1].second = 'B';
friends[2].second = 'C';
sort(friends.begin(), friends.end());
cout << friends[1].second << '\n';
}