TwoStringMasks
SRM 392 · 2008-03-06 · by darnley
Problem Statement
You are given two
You must replace each asterisk with a sequence of letters (possibly of zero length). The resulting two strings must be equal.
Return the shortest possible resulting string. If it is impossible to make the strings equal, return "impossible" (quotes for clarity) instead.
Constraints
- s1 will contain between 1 and 50 characters, inclusive.
- s2 will contain between 1 and 50 characters, inclusive.
- s1 and s2 will contain only uppercase letters ('A'-'Z') and asterisks ('*').
- s1 and s2 will contain exactly one asterisk each.
"TOPC*DER" "T*PCODER" Returns: "TOPCODER"
Each of the asterisks should be replaced with an "O".
"HELLO*" "HI*" Returns: "impossible"
No matter how you replace the asterisks, the second characters of the strings will differ. So it is impossible to make the strings equal.
"GOOD*LUCK" "*" Returns: "GOODLUCK"
The first asterisk should be replaced with an empty string.
"*SAMPLETEST" "THIRDSAMPLE*" Returns: "THIRDSAMPLETEST"
"*" "*" Returns: ""
Submissions are judged against all 135 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TwoStringMasks with a public method string shortestCommon(string s1, string s2) · 135 test cases · 2 s / 256 MB per case