首页 > 其他 > 详细

UVA10340 All in All子序列

时间:2015-04-27 00:01:17      阅读:365      评论:0      收藏:0      [点我收藏+]

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


输入两个字符串s和t,判断是否可以从t中删除一个或多个字符(其他字符顺序不变),得到s。


 1 #include<iostream>
 2 
 3 int main()
 4 {
 5     using namespace std;
 6     char a[100010], b[100010];
 7     int num1 = strlen(a);
 8     int num2 = strlen(b);
 9     int i, j;
10     cin >> a >> b;
11     for (i = 0, j = 0; i < num1&&j < num2;)
12     {
13         
14         if (a[i] == b[j])     //满足条件  i加1,j加1
15         {
16             i++; j++;
17         }
18         else j++;       //否则 j+1,直到找到 a[i]==b[j]
19         
20     }
21     if (i == num1)
22         cout << "bingo!";
23     else cout << "wrong!";
24     system("pause");
25         return 0;
26 }

 

UVA10340 All in All子序列

原文:http://www.cnblogs.com/ghost-song/p/4458586.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!