Description
You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string.
你設計了一種新的加密技術,該技術通過在訊息字串之間插入隨機生成的字串來對消息進行編碼。由於未解決專利問題,我們將不詳細討論如何生成字串。但是,要驗證您的方法,有必要寫一個程式來檢查訊息是否真正編碼在最終字串中。
Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s.
給定兩個字串s和t,您必須確定s是否為t的原始訊息字串,即是否可以從t中刪除字元以使其剩餘字元串聯爲s。
Input
The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.
輸入包含多行。每行兩個字串s和t,s和t只會有英文字母。
Output
For each test case output, if s is a subsequence of t.
對於每行輸入如果s是t的原始訊息字串輸出"Yes",否則輸出"No"。
Sample Input 1
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter
Sample Output 1
Yes
No
Yes
No
Hint
Using two variables to traverse both strings, if we can traverse string "s" completely, it means that "s" is the original message of "t".
用兩個變數分別走訪兩個字串,如果可以把 s 走訪完,代表s是t的原始訊息。
#include<stdio.h>
#include<string.h>
int main(){
char s[100], t[100];
while( scanf("%s %s", s, t) == 2 ){
int sindex = 0;
for( int i = 0 ; i < strlen(t) ; i++ ){
if( t[i] == s[sindex] ){
sindex++;
if( sindex == strlen(s) ) {
break;
}
}
}
if( sindex == strlen(s) )
printf( "Yes\\n" );
else
printf( "No\\n" );
}
return 0;
}