POJ 1936 - All In ALL

Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

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.

Input

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace.The length of s and t will no more than 100000.

Output

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No


  介个介个。。。就是在一个字符串里面找另外一个嘛,有大牛说可以用动态规划找最长公共子列,可惜动态规划没学会,用这个比较笨的方法吧~~
字符串 a和 b 将a中的每一个字符拿出来到b中去找,找到以后,记录当前的位置,下一次比较a中下一个字符时,从记录的位置开始寻找,一直到a中所
有的字符全部找完,就bingo啦~~~当然,全部找到就是yes咯~,以下是代码,路过的求指导~
 1 #include<stdio.h>
 2 #include<string.h>
 3 char a[1000001],b[1000001];
 4 int main()
 5 {
 6     int i,j,k,m,p;
 7     while(scanf("%s %s",a,b)!=EOF)
 8     {
 9         k=strlen(a);
10         m=strlen(b);
11         p=0;
12         for(i=0;i<k;++i)
13         {
14             for(j=p;j<m;++j)
15             {
16                 if(a[i]==b[j])
17                 {
18                     p=j+1;
19                     break;
20                 }
21             }
22             if(j>=m) break;
23         }
24         if(i<k) printf("No\n");
25         else printf("Yes\n");
26     }
27     return 0;
28 }
解题代码


时间复杂度自己分析吧。。。。


posted @ 2013-07-16 19:41  15HP_EPM测试4_王晓  阅读(155)  评论(3编辑  收藏  举报