Quantcast
Viewing all articles
Browse latest Browse all 39796

TWOSTR - Editorial

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


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>