CF1462B
链接题意就是给你一个字符串,问你至多删一个子串能不能变成2020.
分析
这个题目其实还是比较简单的,不知道别人怎么做的,我是这样考虑的。考虑这个最后的答案2020从哪里开始,比如头部没有,那答案必然是最后四个字母是2020,如果开始有个2,那么后面三个就得是020,如果开始是202,那么最后一个就要是0,如果开始就是2020,那么后面就不用考虑。就这样判断一下就好了。
#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;
const char *const YES="YES";
const char* const NO="NO";
while(T--){
int len;cin>>len;
string s;cin>>s;
if(s[0]!='2'){
if(s[len-4]=='2'&&s[len-3]=='0'&&s[len-2]=='2'&&s[len-1]=='0'){
puts(YES);
}
else puts(NO);
}else{
bool ac=false;
if(s[len-3]=='0'&&s[len-2]=='2'&&s[len-1]=='0')ac=true;
if(s[1]=='0'){
if(s[len-2]=='2'&&s[len-1]=='0')ac=true;
if(s[2]=='2'){
if(s[len-1]=='0')ac=true;
if(s[3]=='0')ac=true;
}
}
if(ac)puts(YES);
else puts(NO);
}
}
};