Official

A - OS Versions Editorial by en_translator


For beginners

There are several approaches to this problem.

Approach 1. Casework

The problem can be solved by considering the \(9\) possible cases.
If we notice that there are only \(3\) cases whose answer is No, the conditional branches can be reduced. The sample code adopts this idea.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  string x,y;
  cin >> x >> y;
  if(x=="Ocelot" && y=="Serval"){cout << "No\n";}
  else if(x=="Ocelot" && y=="Lynx"){cout << "No\n";}
  else if(x=="Serval" && y=="Lynx"){cout << "No\n";}
  else{cout << "Yes\n";}
  return 0;
}

Approach 2. Represent the versions by numbers

By assigning numbers to the versions in chronological order, the problem can be reduced to an integer comparison.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  map<string,int> mp;
  mp["Ocelot"]=1;
  mp["Serval"]=2;
  mp["Lynx"]=3;

  string x,y;
  cin >> x >> y;
  if(mp[x]>=mp[y]){cout << "Yes\n";}
  else{cout << "No\n";}
  return 0;
}

Approach 3. Variant of Approach 2

By altering the first character of Lynx, the problem can be boiled down to a lexicographical comparison of the first letter. This approach helps reducing the amount of code.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  string x,y;
  cin >> x >> y;
  if(x[0]=='L'){x[0]='Z';}
  if(y[0]=='L'){y[0]='Z';}
  if(x[0]>=y[0]){cout << "Yes\n";}
  else{cout << "No\n";}
  return 0;
}

posted:
last update: