ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2021-03-06

2021-03-06 15:32:45  阅读:191  来源: 互联网

标签:03 06 string NO Polycarp 2021 && printf YES


D - Last Year’s Substring 补题

Polycarp has a string s[1…n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):

Polycarp selects two numbers i and j (1≤i≤j≤n) and removes characters from the s string at the positions i,i+1,i+2,…,j (i.e. removes substring s[i…j]). More formally, Polycarp turns the string s into the string s1s2…si−1sj+1sj+2…sn.
For example, the string s=“20192020” Polycarp can turn into strings:

“2020” (in this case (i,j)=(3,6) or (i,j)=(1,4));
“2019220” (in this case (i,j)=(6,6));
“020” (in this case (i,j)=(1,5));
other operations are also possible, only a few of them are listed above.
Polycarp likes the string “2020” very much, so he is wondering if it is possible to turn the string s into a string “2020” in no more than one operation? Note that you can perform zero operations.

The first line contains a positive integer t (1≤t≤1000) — number of test cases in the test. Then t test cases follow.

The first line of each test case contains an integer n (4≤n≤200) — length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.

For each test case, output on a separate line:

“YES” if Polycarp can turn the string s into a string “2020” in no more than one operation (i.e. he can perform 0 or 1 operation);
“NO” otherwise.
You may print every letter of “YES” and “NO” in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO

#include <stdio.h>
int main(){
	int k,t;
	scanf("%d",&k);
	for(t=0;t<k;t++){
		int n,i;
		scanf("%d",&n);
		getchar();
		char a[1000];
		scanf("%s",&a);
		if(a[0]=='2'&&a[1]=='0'&&a[2]=='2'&&a[3]=='0'){
			printf("YES\n");
		}else if(a[0]=='2'&&a[1]=='0'&&a[2]=='2'&&a[n-1]=='0'){
			printf("YES\n");
		} else if(a[0]=='2'&&a[1]=='0'&&a[n-2]=='2'&&a[n-1]=='0'){
			printf("YES\n");
		}else if(a[0]=='2'&&a[n-3]=='0'&&a[n-2]=='2'&&a[n-1]=='0'){
			printf("YES\n");
		}else if(a[n-4]=='2'&&a[n-3]=='0'&&a[n-2]=='2'&&a[n-1]=='0'){
			printf("YES\n");
		}  else{
			printf("NO\n");
		} 
	}
	return 0;
}

标签:03,06,string,NO,Polycarp,2021,&&,printf,YES
来源: https://blog.csdn.net/weixin_51592478/article/details/114443128

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有