hyunjin

[C++][비교,논리 연산] 본문

알고리즘 연습/코드업

[C++][비교,논리 연산]

_h.j 2020. 9. 4. 11:36
728x90

[1053]

#include <bits/stdc++.h>

using namespace std;
int main(){
	int a;
	scanf("%d %d",&a);
	cout<<!a;
	return 0;
}

0이면 1로 1이면 0으로 출력하기

 

 

 

[1055]

#include <bits/stdc++.h>

using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	cout<< (a || b);
	return 0;
}

왜인지 모르겠지만 출력할 때 ()를 빼니 0 1 input으로 넣었을 때 0이 나온다.

왜지?

 

 

 

[1057] 같을 때 참  

#include <bits/stdc++.h>

using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	cout<< (a == b);
	return 0;
}

!(a==b) 이걸로 하면 xor 연산자 되겠다.

 

 

[1058] 모두 거짓 일 때만 참

#include <bits/stdc++.h>

using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	cout<< !(a || b);
	return 0;
}

0 0 일때만 1이 나오게, 하나라도 참이 있다면 거짓.

!a && !b도 같은 표현

728x90