Official

A - Jiro Editorial by en_translator


For beginners

This problem has various solutions.

One solution is to implement a conditional branch for all the eight possible input (among which six are consistent and can actually be the input). This can be done with an if statement, but it’s a bit cumbersome.

Here is a bit cleverer solution:

  • If \(S_\mathrm{AB}\neq S_\mathrm{AC}\): A is the middle son.
  • Otherwise, if \(S_\mathrm{AB}= S_\mathrm{BC}\): B is the middle son.
  • Otherwise: C is the middle son.

This casework is simpler.

We can alternatively enumerate all possible six relations and check if each is consistent with the input.

The following sample code implements the simple casework.

Sample code (C++):

#include <bits/stdc++.h>
using namespace std;

int main() {
    char a, b, c;
    cin >> a >> b >> c;
    if(a != b)
        cout << "A" << endl;
    else if(a == c)
        cout << "B" << endl;
    else
        cout << "C" << endl;
}

posted:
last update: