Read Me!


本網誌之內容皆可自由複製
唯須標明出處且不可作商業用途

2016年7月11日 星期一

UVa 10340 All in all

UVa 10340 All in all


題意:

輸入一個 目標字串A 和一個 字串B
求是否可以透過刪除 B 中的字元來得到 A


解題:

很簡單,按照目標字串的順序來搜尋就好了

這邊運用了字串結尾是虛字元'\0'(ACSII碼=0)
及c/c++ 0=false的規定

//UVa 10340 All in all
#include <cstdio>
#include <cstring>
char sub[100000], str[100000];
int main() {
while(scanf("%s%s", sub, str) == 2) {
int j = 0;
for (int i = 0; str[i]; ++i) {
if(str[i] == sub[j]) j++;
}
printf("%s\n", sub[j] ? "Yes" : "No");
}
return 0;
}
view raw AllInAll.cpp hosted with ❤ by GitHub

沒有留言:

張貼留言