https://codeforces.com/contest/1796/problem/A
Problem - A - Codeforces
codeforces.com
난이도 : A
유형 : 문자열, 탐색
문제 풀이
테스트 케이스가 돌기전에 1 ~ 2046까지의 FB 문자열을 미리 만들어 놓고
테스트 케이스마다 미리 만들어 놓은 문자열에 입력으로 들어온 문자열이 포함되어 있는지 판별하면 된다.
코드
import java.io.BufferedReader
import java.io.InputStreamReader
var str: String = ""
var t: Int = 0
var k: Int = 0
var input: String = ""
fun solution() = with(BufferedReader(InputStreamReader(System.`in`))) {
var sb = StringBuilder()
for (i in 1..2046) {
if (i % 15 == 0) {
str += "FB"
} else if (i % 3 == 0) {
str += "F"
} else if (i % 5 == 0) {
str += "B"
}
}
t = readLine().toInt()
while (t-- > 0) {
k = readLine().toInt()
input = readLine()
if (!str.contains(input)) {
sb.append("NO")
} else {
sb.append("YES")
}
sb.append('\n')
}
print(sb)
}
fun main() {
solution()
}
'Algorithm, Problem Solving > codeforces' 카테고리의 다른 글
[codeforces][Kotlin] 703A - Mishka and Game (0) | 2023.03.28 |
---|---|
[codeforces][Kotlin] 313A - Ilya and Bank Account (0) | 2023.03.27 |
[codeforces][Kotlin] 466A - Cheap Travel (0) | 2023.03.25 |
[codeforces][Kotlin] 189A - Cut Ribbon (0) | 2023.03.24 |
[Codeforces][Kotlin] 32B - Borze (0) | 2023.03.21 |
댓글