Patterns
SRM 124 · 2002-12-12 · by dgoodman
Problem Statement
Create a class Patterns that contains the method firstMatch that takes a
Constraints
- s contains between 1 and 50 characters, inclusive.
- Each character in s is a lowercase letter 'a'-'z'.
- pat contains between 1 and 50 characters, inclusive.
- Each character in pat is an uppercase letter 'A'-'Z'.
"nowisthetree" "ABCA" Returns: 5
"thet" and "etre" both satisfy the pattern ABCA. "thet" is first, starting at index 5.
"abcdefghijklmnop" "ZYX" Returns: 0
Every 3 letter substring of this string s satisfies the pattern ZYX. "abc" is first.
"abcdefghijklmnop" "QQ" Returns: -1
"cabbabbabbaqc" "ABBAC" Returns: 7
"abba" "ABBAC" Returns: -1
"cd" "CDCD" Returns: -1
No substring of "cd" can have enough letters to match CDCD.
Submissions are judged against all 24 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Patterns with a public method int firstMatch(string s, string pat) · 24 test cases · 2 s / 256 MB per case