2020을 한번만 제외하고 만들 수 있는지 여부를 확인하는 문제입니다. 중간에 한번밖에 못띄우니 앞, 뒤에 2020의 모든 숫자가 존재해야합니다.
import sys
input = sys.stdin.readline
for test in range(int(input())):
n = int(input())
s = input().rstrip()
answer = '2020'
if s[0] + s[-3:] == answer or s[:2] + s[-2:] == answer or s[:3] + s[-1] == answer or s[:4] == answer or s[-4:] == answer:
print("YES")
else:
print("NO")
'practivceAlgorithm > codeforce' 카테고리의 다른 글
[codeforce][Python] #690 E1. Close Tuples (easy version) (0) | 2021.12.07 |
---|---|
[codeforce][Python] #690 C. Unique Number (0) | 2021.12.07 |
[codeforce][Python] #690 A. Favorite Sequence (0) | 2021.12.07 |
[Codeforce][Python] #702 F. Equalize the Array (0) | 2021.11.07 |
[Codeforce][Python] #702 D. Permutation Transformation (0) | 2021.11.07 |