 # TWOSTR - Editorial

Author: Tasnim Imran Sunny
Tester: Istvan Nagy
Editorialist: Lalit Kundu

Cakewalk

### PREREQUISITES:

basic programming, strings

### PROBLEM:

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.

### EXPLANATION:

================
We can reduce problem of matching two strings X and Y to matching individual characters for each index 0 \le i < N. If all characters can be matched, then we can say that both strings can also be matched.

#### MATCHING A CHARACTER

We need to check if two characters a and b can be matched or not. If either of them is ‘?’, then we can always match them by filling it with the required value. If both are ‘?’, still we can give any same value to both of them.

If both are not ‘?’, then we just need to check if the current values are same or not.

For implementation, see setter’s commented code.

### AUTHOR’S, TESTER’S SOLUTIONS:

1 Like

such a bonus question!

can any one plzz tell what is wrong in my code

#include<stdio.h>
int main()
{
int t,i,flag;
char x,y;
scanf("%d",&t);
while(t–)
{
flag=0;
scanf("%s",x);
scanf("%s",y);
for(i=0;(x[i]!=NULL)&&(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;
}

you have to declare your char ARRAYS as x and y as strings have one character extra regarded as NULL

2 Likes

yes it worked with 11…

#include
#include<string.h>
using namespace std;
int main()
{
int t,flag,i;
char str1,str2;
cin>>t;
while(t–)
{
cin>>str1;
cin>>str2;
int length=strlen(str1);
for(i=0;i<length;i++)
{

``````	**strong text**	if(str1[i]=='?'||str2[i]=='?')
flag=1;
else if(str1[i]==str2[i])
flag=1;
else
{
flag=0;
break;
}

}
if(flag==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
``````

}

#include<stdio.h>
int length(char str[]);
int main()
{
char string1,string2;
int i,sum=0,t,count;
scanf("%d",&t);
while(t–)
{
scanf("%s%s",&string1,&string2);
count=length(string1);
for(i=0;i<count;i++)
{
if(string1[i]==string2[i])
{
sum++;
}
else if(string1[i]==’?’)
{
sum++;
}
else if(string2[i]==’?’)
{
sum++;
}
}
if(sum==count)
{
printf(“Yes\n”);
}
else{
printf(“No\n”);
}
sum=0;
}
return 0;
}
int length(char str[])
{
int count=0;
int i=0;
while(str[i]!=’\0’)
{
count++;
i++;
}
return count;
}
what is wrong is this code why wrong anser are come

can anyone please tell me what is wrong with this code?

`````` for _ in range(int(input())):
x=list(input())
y=list(input())
a=1
for i,j in zip(x,y):
if i==j or i=="?" or j=="?":
continue
else:
print("NO")
a=0
break
if a!=0:
print("Yes")``````

the print(i,j) is just for debugging purposes

//