All in all

题目要求(英文)
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.
翻译
您设计了一种新的加密技术,通过在消息的字符之间以巧妙的方式插入随机生成的字符串来对消息进行编码。由于未决的专利问题,我们不会详细讨论如何生成字符串并将其插入原始消息中。但是,为了验证您的方法,有必要编写一个程序来检查消息是否真的编码在最后一个字符串中。 给定两个字符串s和t,您必须决定s是否是t的子序列,也就是说,如果您可以从t中删除字符,那么剩余字符的串联就是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".

使用字符数组输入s和t,然后通过两层for循环查找t中是否包括s[x],如果包括则count++;
(由于s和t中字符顺序可能不一样,所以每次查询都应该接着上次查到的位置的下一个继续查,所以除了第一次是从y=0开始其余每次都是从y+1开始);
最后如果count的值等于s中的字符个数,说明t包含s,输出yes;

#include<iostream>
#include<cstring>
char s[10000],t[100000];
using namespace std;
int main()
{
 while(cin>>s>>t)
 { 
 int i,j;//is jt
 i=strlen(s);
 j=strlen(t);
 int count=0;
 int y=0;
 for(int x=0;x<i;x++)
 {
  for(y;y<j;y++)
  {
   if(s[x]==t[y])
   {
    y++;
    count++;
    break;
   }
  }
  }
  if(count==i)
  {
   cout<<"Yes"<<endl;
   } 
   else
   {
    cout<<"No"<<endl;
   }
   } 
 return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值