Problem B: 2020DLOI初中 第二题 二零二零(1.3)

Problem B: 2020DLOI初中 第二题 二零二零(1.3)

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

      给出一个字符串S,其中满足S的每一个字符都是数字字符,你要删除S的连续一段字符(也可以删除0个字符),使得剩下的字符依次连接起来的字符串是“2020,可以做到吗?如果可以做到输出“YES”,否则输出“NO”。

Input

第一行,一个整数G,表示有G组测试测试。1<=G<=10

每组测试格式如下:

第一行,一个整数n,表示字符串S的长度。1<=n<=200

第二行,字符串S

Output

G行,每行一个字符串,“YES”或“NO”,双引号不用输出。

Sample Input Copy

5
8
20192020
8
22019020
4
2020
5
20002
6
729040

Sample Output Copy

YES
YES
YES
NO
NO

HINT

n=int(input())
for i in range(n):
  L=int(input())
  s=input()
  if L<4 :
    print('NO')
    continue
  ans='NO'
  if s[0]=='2' and s[1]=='0' and s[2]=='2' and s[3]=='0' : ans='YES'
  if s[0]=='2' and s[1]=='0' and s[2]=='2' and s[-1]=='0' : ans='YES'
  if s[0]=='2' and s[1]=='0' and s[-2]=='2' and s[-1]=='0' : ans='YES'
  if s[0]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0' : ans='YES'
  if s[-4]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0' : ans='YES'
  print(ans)