Subsequence

Subsequence

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交:19            测试通过:13

描述

We say that a string A is a subsequence of another string B,if there is a number sequence C which satisfied the following conditions:

a.C has exactly length(A) numbers;

b.0<C[0]<c[1]<…<c[Lenth(A)-1]<Lenth(B);

c.A[i]=B[C[i]] for each number i(i<=i<Lenth(A)).

For example, “abcd” is a subsequense of”aaaaaabbbcd”,while “abcd” is not a subquence of “aaaaacccdb”.Of course any string is a subsequence of itself.

In this problem,you are given a long string A and any short string Bi.You need to write a fast program which tells whether Bi is a consequence of A.

输入

On the first line input,there is a positive integer T<=20 specifying the number of test cases fpllow.

The first line eace tst case give the string A.The second line contains an integer M(0<M<=10000),which is the number of short string Bi.And the next following M lines each contain a string Bi.

The length of A will be no more than100000 and the length of all Bi will be no more than 50.All the string will have at least one letter,and all the letters will appear in lowercase

输出

The putout of eace test case contains M+1 lines.The first line should be “Case X:”( quotes for clariy) where X is the number of the test case(starting at 1).

The M lines follow:for each Bi,if it’s a subsequence of A outputb”Yes”,otherwise output “No”.

样例输入

2
subsequence
2
sequence
bus
problem
1
rom

样例输出

Case 1:
Yes
No
Case 2:
Yes

#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<string>
using std::string;

bool check(const string& src, const string& str){
	string::size_type src_len(src.length()), str_len(str.length());
	for (string::size_type src_counter(0), str_counter(0); str_counter != str_len; ++str_counter){
		if (src[src_counter] == str[str_counter]){
			++src_counter;
		}
		if (src_counter == src_len){
			return true;
		}
	}
	return false;
}

int main(void){
	string src, str;
	unsigned short int times, sub_times;
	cin >> times;
	for (unsigned short int counter(0); counter != times; ++counter){
		cin >> str;
		cin >> sub_times;
		cout << "Case " << counter + 1 << ":" << endl;
		while (sub_times--){
			cin >> src;
			cout << (check(src, str) ? "Yes" : "No") << endl;
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值