×

# 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:

This question is marked "community wiki".

3.0k93164187
accept rate: 12%

19.8k350498541

 0 such a bonus question! answered 24 Aug '15, 01:23 226●2●9 accept rate: 9%

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[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;
}


254
accept rate: 0%

2

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

(26 Sep '15, 20:03)

yes it worked with 11....

(27 Sep '15, 17:13)

# 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[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;


}

6111
accept rate: 0%

# 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[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

1
accept rate: 0%

 0 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")  answered 23 Jan, 19:54 1●1 accept rate: 0% the print(i,j) is just for debugging purposes (23 Jan, 19:55)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,651
×1,647
×827
×349
×104
×81
×1

question asked: 23 Aug '15, 19:02

question was seen: 4,452 times

last updated: 23 Jan, 20:26