Official
A - Not Editorial
by
A - Not Editorial
by
ynymxiaolongbao
問題文で指示された通りに、if文を使って条件分岐を行うことで正解することができます。
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
if(x==0)cout<<1<<"\n";
if(x==1)cout<<0<<"\n";
}
また、\(x=0\) のとき \(1\) で \(x=1\) のとき \(0\) になるような数式を使う方法もあります。
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
cout<<1-x<<"\n";
}
\(1-x\) の他に、not \(x\) 、\(x\) xor \(1\) などが考えられます。
not は否定、xor は排他的論理和を表します。
posted:
last update: