題目鏈接:All in All
Problem E
All in All
Input: standard input
Output: standard output
Time Limit: 2 seconds
Memory Limit: 32 MB
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.
Input Specification
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.
Output Specification
For each test case output, if s is a subsequence of t.
Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter
Sample Output
Yes
No
Yes
No
Source: ULM Local Contest
Source
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Problem Solving Paradigms :: Greedy :: Non Classical, Usually Harder
簡單字符串處理,不說了,直接上代碼(RE好多次,,哭。。):
/************************************************************************* > File Name: a.cpp > Author: zzuspy > Mail: [email protected] > Created Time: 2014年12月01日 星期一 20時02分23秒 ************************************************************************/ #include#include #include #include #include #include #include #include #define LL long long #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) using namespace std; char a[100005], b[100005]; //題目沒說多大,我之前只開10005,RE到死啊!!!! int main() { while(scanf("%s %s", a, b)!=EOF) { int i, j, lena = strlen(a), lenb = strlen(b); if(lena>lenb) { printf("No\n"); continue; } for(i = 0, j = 0; b[j]!='\0'&&i lenb-j)break; if(a[i]==b[j]) i++; } if(i==lena)printf("Yes\n"); else printf("No\n"); } return 0; }