Playful String

QUESTION

KillCode is trying to learn strings but failing to solve the recursive approach given by his Teacher. His Teacher gave him a string consisting of lower case alphabets only , He asked to find a substring in the given string after removing any characters from the original string . \n\nFor example if the string is\n\n\” Cypher\” and the substring is \”yer\”, Kill code can remove p,h from the string and can form the given substring.\n\nNow the Teacher got impressed from Killcode and decided to increase the difficulty by asking to find the substring and reverse of substring in given string. If both substring can be formed by a given string by removing certain characters , print \”GOOD STRING \” else print \”BAD STRING\”.\n\nContraints\n\n1<=t<=10\n1<=|s|<=100000\n\nInput -\nFirst line contains integer t denoting the test cases, each test case contains two lines containing two strings.\n\nOutput-\nPrint \”GOOD STRING\”(without quotes) both strings can be formed by given string else print \”BAD STRING\”.

ANSWER

#include<bits/stdc++.h>
#define Casese int tt;cin>>tt;while(tt--)
using namespace std;
int main(){Casese{
    string s,c;
    cin>>s>>c;
    int i,j,l=0,t,t1;
    for(i=0;i<c.length();i++){
        for(j=l;j<s.length();j++){
            if(s[j]==c[i]){
                t=1;
                l=j+1;
                break;
            }else{
                t=0;
            }
        }if(t==0){
            break;
        }
       
    }
    string s1;
  for(i=0;i<s.length();i++){
      s1=s1+s[s.length()-i-1];
  }
  l=0;
 
 for(i=0;i<c.length();i++){
        for(j=l;j<s1.length();j++){
            if(s1[j]==c[i]){
                t1=1;
                l=j+1;
                break;
            }else{
                t1=0;
            }
        }if(t1==0){
            break;
        }
       
    }
     
 if(t1==1&&t==1){
     cout<<"GOOD STRING";
 }else{
     cout<<"BAD STRING";
 }
 cout<<"\n";
   
}
    return 0;
          }
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.