Official
B - Cycle Hit Editorial by en_translator
Various approaches are possible, among which the condition of being No
is probably the easiest.
The answer is No
if and only if
- there exist \((i, j)\) such that \(S_i = S_j (i \neq j)\).
This way, we can implement it as follows.
Sample code in C++:
#include<bits/stdc++.h>
using namespace std;
signed main(){
vector<string>s(4);
for(int i=0;i<=3;i++)cin>>s[i];
for(int i=0;i<=3;i++){
for(int j=0;j<=3;j++){
if(i!=j && s[i]==s[j]){
cout<<"No"<<endl;
return 0; // terminate the program
}
}
}
cout<<"Yes"<<endl;
return 0;
}
posted:
last update: