Solutio of 10340 - All in All

Problem Description
source:https://uva.onlinejudge.org/external/103/10340.html

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. Input is terminated by EOF. 

Output 

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


Solution :
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main()
{
    long int i,j;
    char seq[100000], sub[100000];
    while(scanf("%s%s",&seq,&sub)==2)
    {
        j=0;
        for(i=0;sub[i]!='\0';i++)
        {
            if(seq[j]!='\0')
            {
                if(seq[j]==sub[i])
                {
                    j+=1;

                }
            }
            else
                break;
        }
        if(j==strlen(seq))
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience