TWOSTR - Editorial

basic-prog
cakewalk
cook61
editorial
implementation
strings
twostr

#1

PROBLEM LINK:

Practice
Contest

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

DIFFICULTY:

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:

setter
tester


#2

such a bonus question!


#3

can any one plzz tell what is wrong in my code
it is showing wrong answer

#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*!=NULL)&&(flag==0);i++)
{
if(x*!=’?’&&y*!=’?’)
{
if(x*!=y*)
{
flag=1;
}
}
}
if(flag==0)
printf("Yes
");
else
printf("No
");
}
return 0;
}


#4

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

	**strong text**	if(str1*=='?'||str2*=='?')
			flag=1;
		else if(str1*==str2*)
			flag=1;
		else
		{
			flag=0;
			break;
		}
	
	}
	if(flag==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}
return 0;

}


#5

#include<stdio.h>
int length(char str[]);
int main()
{
char string1[10],string2[10];
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*==string2*)
{
sum++;
}
else if(string1*==’?’)
{
sum++;
}
else if(string2*==’?’)
{
sum++;
}
}
if(sum==count)
{
printf("Yes
");
}
else{
printf("No
");
}
sum=0;
}
return 0;
}
int length(char str[])
{
int count=0;
int i=0;
while(str*!=’\0’)
{
count++;
i++;
}
return count;
}
what is wrong is this code why wrong anser are come


#6

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")

#7

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


#8

yes it worked with 11…


#9

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