UVA - 10340 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


题目:判断a串是不是b串的子串。

解析:遍历所有的字母,用string find进行查找,找到了就查找该位置的下一个位置,如果没找到该字母,就返回false,全部都找到就返回true。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
string s,t;
bool judge() {
	int pos = -1;
	for(int i = 0; i < s.size(); i++) {
		pos = t.find(s[i],pos+1);
		if(pos == string::npos) {
			return false;
		}
	}
	return true;
}
int main() {
	while(cin >> s) {
		cin >> t;
		if(judge()) {
			cout << "Yes" << endl;
		}else {
			cout << "No" << endl;
		}
	}
	return 0;
}

你可能感兴趣的:(in,uva,all,all,10340)