Problem Statement
Hero has a String pattern.
Each character in pattern is one of '0', '1', '2', and '3'.
Hero also has a String S of wildcard characters.
Each character of S is either 'a' or 'b'.
You are allowed to modify S by changing some (possibly none or all) characters to their uppercase versions: that is 'a' to 'A' and 'b' to 'B'.
The meaning of the wildcard characters in S is as follows:
- 'a' matches small digits: '0' and '1'
- 'A' matches big digits: '2' and '3'
- 'b' matches even digits: '0' and '2'
- 'B' matches odd digits: '1' and '3'
Definition
- Class:
- Softmatchd2
- Method:
- count
- Parameters:
- String, String
- Returns:
- int
- Method signature:
- int count(String S, String pattern)
- (be sure your method is public)
Constraints
- S will contain between 1 and 50 characters, inclusive.
- Each character in S will be either 'a' or 'b'.
- pattern will contain between 1 and 50 characters, inclusive.
- Each character in pattern will be between '0' and '3', inclusive.
- pattern will be at most as long as S.
Examples
"aba"
"13"
Returns: 2
The string "aBA" contains two occurrences of the given pattern: one at position 0 and the other at position 1."abbaa"
"123"
Returns: 2
One string that contains two occurrences of the given pattern is the string "abBAA". One occurrence is at position 0 (small digit, even digit, odd digit), the other is at position 2 (odd digit, large digit, large digit)."aaaa"
"1230"
Returns: 1
"ababbaaba"
"0311"
Returns: 3
"aabbbabbbb"
"332233"
Returns: 2
"aaaabbbababababababaaabaa"
"02232"
Returns: 9