链接:https://vjudge.net/problem/UVA-10340
同时遍历两个字符串即可,同时向前进行。
遇见相等时,都向前进1
不相等时,字串不动,父串进1.
要注意避免数组越界。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define maxn 1000000
int main() {
freopen("i.txt","r",stdin);
char s1[maxn],s2[maxn];
while(~scanf("%s%s",s1,s2)) {
int len1, len2, i1 = 0, i2 = 0;
for(len1 = 0; s1[len1]; len1++);
for(len2 = 0; s2[len2]; len2++);
while(i1 < len1 && i2 < len2) {
while(s1[i1]!=s2[i2] && i1<len1 && i2<len2)
i2++;
if(s1[i1]==s2[i2] && i1<len1 && i2<len2){
i1++;
i2++;
}
}
if(i1==len1) printf("Yes\n");
else printf("No\n");
}
}