AT_abc360_b [ABC360B] Vertical Reading题解
一、题目大意
总结:给定两个字符串
二、问题分析
1.字符串预处理
对于字符串
string S;
cin>>S;
int len=S.size();
S='#'+S;
//S="#atcoder"
2.枚举 w 和 c 求新字符串 K
以字符串 "
如果
3.确定每组中选择的字符
如果
在枚举时,可以从下标
string K="";
for(int g=c;g<=len;g+=w){
K+=S[g];
}
4.采用 提前截止法 或 假设法 输出答案
(1)提前截止法
满足条件,输出并
(2)假设法
新建布尔型变量
三、参考代码
#include<iostream>
#include<string>
using namespace std;
string S,T;
signed main() {
cin>>S>>T;
int len=S.size();
S='#'+S;
for(int w=1;w<len;w++){
for(int c=1;c<=w;c++){
string K="";
for(int g=c;g<=len;g+=w) K+=S[g];
if(K==T){//提前截止法
cout<<"Yes";
return 0;
}
}
}
cout<<"No";
return 0;
}