(代码实现)北京大学-JudgeOnline-1936

来源:互联网 发布:会计视频课程 知乎 编辑:程序博客网 时间:2024/04/29 15:37

题目:

All in All
Time Limit:1000MS  Memory Limit:30000K
Total Submit:5227 Accepted:1975

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

 

Sample Output

 

代码:

//AC

#include <stdio.h>
#include <string.h>

char s[1000000],t[1000000];

int main()
{
 long sl,tl,i,j;
 while(scanf("%s %s",s,t)!=EOF)
 {
  i=0;
  j=0;
  sl=strlen(s);
  tl=strlen(t);

  while(1)
  {
   if(s[i]==t[j])
   {
    i++;
    j++;
   }
   else
   {
    j++;
   }
  
   if(i==sl && j<tl+1)
   {
    printf("Yes/n");
    break;
   }
  
    if(i<sl && j==tl)
   {
    printf("No/n");
    break;
   }
  }

 }
 return 0;

 

思路:

这个题目,我觉的只能是一个一个字符的比较了,想不出有更好的办法了,不知道大家怎么想的;

YesNoYesNo

sequence subsequenceperson compressionVERDI vivaVittorioEmanueleReDiItaliacaseDoesMatter CaseDoesMatter
原创粉丝点击