UVa 10340:All in All

來源:互聯網
上載者:User

連結:

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1281

原題:

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

分析與總結:

更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

簡單題,直接判斷一個字串是否是另一個字串的子串。

代碼:

/*  *  UVa: 10340 - All in All  *  Time: 0.008s  *  Author: D_Double  */#include<iostream>  #include<cstdio>  #include<cstring>  using namespace std;  char str1[1000000], str2[1000000];       bool judge(){      int pos=0, i;      for(i=0; i<strlen(str1); ++i){          bool flag=false;          while(pos < strlen(str2)){              if(str2[pos]==str1[i])                  break;              ++pos;          }          if(pos==strlen(str2)) return false;          ++pos;      }      if(i==strlen(str1)) return true;      return false;  }       int main(){      while(scanf("%s %s",str1,str2)!=EOF){          if(judge()) printf("Yes\n");          else printf("No\n");      }      return 0;  }

作者:csdn部落格 shuangde800

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.