POJ 1936 All in All

比較水的題目,對兩個字符串都進行一次遍歷,看看能不能對應起來,比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");
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章