POJ 1936 All in All

来源:互联网 发布:我国银行员工待遇数据 编辑:程序博客网 时间:2024/06/07 02:10

比较水的题目,对两个字符串都进行一次遍历,看看能不能对应起来,比kmp要简单的多

#include <iostream>#include <cstdio>#include <memory.h>#include <string.h>using namespace std;#define maxn 100050int 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");        }    }}
0 0
原创粉丝点击