Problem Description
Chef wants to implement wildcard pattern matching supporting only the wildcard ?. The wildcard character ? can be substituted by any single lower case English letter for matching. He has two strings X and Y of equal length, made up of lower case letters and the character ?. He wants to know whether the strings X and Y can be matched or not.
Input
The first line of input contain an integer T denoting the number of test cases. Each test case consists of two lines, the first line contains the string X and the second contains the string Y.
Output
For each test case, output a single line with the word Yes if the strings can be matched, otherwise output No.
Constraints
1 <= T <= 50
Both X and Y have equal length and the length is between 1 and 10.
Both X and Y consist of lower case letters and the character ?.
Example
Input:
2
s?or?
sco??
stor?
sco??
Output:
Yes
No
Explanation
First Example: There are several ways the two strings can be matched, one of those is "score".
Second Example: There is no way to match the strings.Test Case 1
Input (stdin)2 s?or? sco?? stor? sco??
Expected OutputYes No
Test Case 2
Input (stdin)1 s?or? sco?? stor? sco??
Expected OutputYes
Program
#include <stdio.h> int main() { int t,i,flag; char x[10],y[10]; scanf("%d",&t); while(t--) { flag=0; scanf("%s",x); scanf("%s",y); for(i=0;(x[i]!=0)&&(flag==0);i++) { if(x[i]!='?'&&y[i]!='?') { if(x[i]!=y[i]) { flag=1; } } } if(flag==0) 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.