문제 출처 : https://www.acmicpc.net/problem/13234
언어 : Kotlin
문제 설명 :
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: The field that is the basis of today’s computers.
In boolean arithmetic, instead of infinite numbers we only have 2 values: 0/1, true/false, yes/no, etc. We will use the values true and false in this problem. The two most common operations in boolean arithmetic are AND and OR.
The result of an AND operation is true only if both elements are true. Examples:
- true AND true = true
- true AND false = false
- false AND false = false
The result of an OR operation is true if any of the elements are true. Examples:
- true OR true = true
- false OR false = false
- false OR true = true
In this problem you’ll read one of such operations and write the correct result.
입력 :
Read a single line from the standard input. The line will contain three words with the format:
value1 operation value2. The fields value1 and value2 will be either true or false. The field operation will be either AND or OR.
출력 :
Print either true or false.
제한 사항 :
- 시간 제한 : 2초
- 메모리 제한 : 512MB
입출력 예 :
입력 | 출력 |
true AND true | true |
true OR true | true |
true AND false | false |
false OR true | true |
false AND false | false |
false OR false | false |
풀이 :
단순히 입력받은 텍스트로 and, or 논리연산을 수행하는 문제
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
val bw = BufferedWriter(OutputStreamWriter(System.out))
readLine().split(" ").also {
val a = it[0] == "true"
val b = it[2] != "false"
val result = when (it[1]) {
"AND" -> a && b
"OR" -> a || b
else -> false
}
bw.write("$result")
}
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
28255번: 3단 초콜릿 아이스크림 (0) | 2024.08.13 |
---|---|
18787번: Mad Scientist (0) | 2024.08.13 |
2149번: 암호 해독 (0) | 2024.08.12 |
30889번: 좌석 배치도 (0) | 2024.08.09 |
10927번: MD5 (0) | 2024.08.09 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!