Problem Description
In an attempt to control the rise in population, Archer was asked to come up with a plan. This time he is targeting marriages. Archer, being as intelligent as he is, came up with the following plan:
A man with name M is allowed to marry a woman with name W, only if M is a subsequence of W or W is a subsequence of M.
A is said to be a subsequence of B, if A can be obtained by deleting some elements of B without changing the order of the remaining elements.
Your task is to determine whether a couple is allowed to marry or not, according to Archers rule.
Input
The first line contains an integer T, the number of test cases. T test cases follow. Each test case contains two space separated strings M and W.
Output
For each test case print ""YES"" if they are allowed to marry, else print ""NO"". (quotes are meant for clarity, please dont print them)
Constraints
1 <= T<=100
1<= |M|, |W| <=25000 (|A| denotes the length of the string A.)
All names consist of lowercase English letters only.Test Case 1
Input (stdin)3 john johanna ira ira kayla jayla
Expected OutputYES YES NO
Test Case 2
Input (stdin)3 nivi pavi tifu tifk vishu nisha
Expected OutputNO NO NO
Program
#include <stdio.h> #include<string.h> #define p 25000 int main() { char s1[p],s2[p]; int g=0,i,t,k,h=0; scanf("%d",&t); for(k=1;k<=t;k++) { g=0; h=0; scanf("%s",s1); scanf("%s",s2); for(i=0;s2[i]!='\0' && s1[g]!='\0';i++) { if(s2[i]==s1[g]) { g++; } } for(i=0;s1[i]!='\0' && s2[h]!='\0';i++) { if(s1[i]==s2[h]) h++; } int l=strlen(s1); int l1=strlen(s2); if(l==g || l1==h) printf("YES\n"); else printf("NO\n"); } return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.