A - Chinchirorin Editorial by Mitsubachi
$a,b,c$ のうち、ある $2$ つの目が同じ場合、もう $1$ つの目は $a \oplus b \oplus c$ であることを使うと、答えが $0$ でない場合の処理を簡潔に書くことができます。 ( $A \oplus B$ は $A$ と $B$ の排他的論理和を表します。)
これは $X \oplus X = 0$ であることより分かります。
実装例(C++)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> v(3);
cin>>v[0]>>v[1]>>v[2];
sort(v.begin(),v.end());
if(v[0]!=v[1]&&v[1]!=v[2]){
cout<<0<<endl;
}
else{
//(a^b)でaとbの排他的論理和を表す
cout<<(v[0]^v[1]^v[2])<<endl;
}
}
posted:
last update: