比较水的题目,对两个字符串都进行一次遍历,看看能不能对应起来,比kmp要简单的多
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <string.h>
using namespace std;
#define maxn 100050
int main(){
char str1[maxn],str2[maxn];
while(scanf("%s%s",&str1,&str2)!=EOF){
int loc1=0;
int loc2=0;
int len1 = strlen(str1);
int len2 = strlen(str2);
bool match = false;
while(true){
if(loc1>=len1||loc2>=len2)
break;
if(str1[loc1]==str2[loc2]){
loc1++;
loc2++;
}
else{
loc2++;
}
if(loc1==len1){
match=true;
printf("Yes\n");
}
}
if(!match){
printf("No\n");
}
}
}