Official

A - Five Integers Editorial by en_translator


Initialize a counter with \(0\), inspect \(A, B, C, D\), and \(E\) in this order, and increment the counter by \(1\) every time you encounters an integer you have not seen yet, then we can count the number of distinct integers.

In other words, initialize a counter with \(0\) and perform the following steps:

  • Increment the counter by \(1\) (corresponding to \(A\)).
  • Increment the counter by \(1\) if \(B\) is different from \(A\).
  • Increment the counter by \(1\) if \(C\) is different from \(A\) and \(B\).
  • Increment the counter by \(1\) if \(D\) is different from \(A\), \(B\), and \(C\).
  • Increment the counter by \(1\) if \(E\) is different from \(A\), \(B\), \(C\), and \(D\).

The answer is the final value of the counter.

The “if” above can be implemented with a conditional branch (like if statements), which is a standard feature of programming languages.

The following is a sample code in C++ for this problem.

#include <iostream>
using namespace std;

int main(void)
{
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  
  int ans = 0;
  ans++;
  if(b != a) ans++;
  if(c != a && c != b) ans++;
  if(d != a && d != b && d != c) ans++;
  if(e != a && e != b && e != c && e != d) ans++;
  
  cout << ans << endl;
  return 0;
}

posted:
last update: