※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 13234번 문제인 George Boole이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/13234 

 

13234번: George Boole

George Boole was an English mathematician, educator, philosopher who was born in 1815, 200 years ago. He was the first professor of mathematics at Queen's College, Cork (now University College Cork (UCC)) and is known as the inventor of boolean arithmetic:

www.acmicpc.net

주어지는 두 변수와 연산자를 읽어 문제에 주어진 대로 비트연산을 한 결과를 출력하자.

 

C++에서 and 비트연산은 "&", or 비트연산은 "|"으로 할 수 있다.

 

나올 수 있는 수식의 종류가 8가지 뿐이므로, 단순히 모든 가능한 수식에 대한 답을 하드코딩하는 것으로도 문제를 해결할 수 있을 것이다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

string s1, op, s2;
bool b1, b2;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> s1 >> op >> s2;
	
	if (s1 == "true") b1 = 1;
	if (s2 == "true") b2 = 1;

	if (op == "AND") {
		if (b1 & b2) cout << "true";
		else cout << "false";
	}
	else {
		if (b1 | b2) cout << "true";
		else cout << "false";
	}
}
728x90

+ Recent posts