公式
A - Not 解説 by evima
One can get AC by writing a conditional branch with if statement, just as the problem statement indicates.
Sample code using a conditional branch (C++)
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
if(x==0)cout<<1<<"\n";
if(x==1)cout<<0<<"\n";
}
Also, one may use a formula which becomes \(1\) when \(x=0\) and \(0\) when \(x=1\).
Sammple code using a formula(C++)
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
cout<<1-x<<"\n";
}
Other than \(1-x\), one can also use “not \(x\)” and “\(x\) xor \(1\).”
Here, “not” denotes negation and “xor” denotes exclusive logical sum.
投稿日時:
最終更新: