AutoFix
TCCC '04 Semifinals 3 · 2004-02-23 · by lars2520
Problem Statement
You will be given a
Notes
- The words in dictionary are all lowercase, but applying the transformation should be done without regard to case (see examples)
Constraints
- dictionary will contain between 1 and 50 elements, inclusive.
- Each element of dictionary will contain between 1 and 50 lowercase letters ('a'-'z'), inclusive.
- sentence will contain between 1 and 50 characters, inclusive.
- Each character of sentence will be a letter ('a'-'z' or 'A'-'Z') or a space (' ').
- There will be no leading, trailing, or double spaces in sentence.
- times will contain the same number of elements as sentence has characters.
- Each element of times will be between 0 and 1,000,000, inclusive.
- times will be sorted in strictly ascending order.
"Th EProblem"
{5,46,55,75,101,130,453,531,692,780,1003}
{"the","problem","th"}
Returns: "ThE Problem"
The space is typed after 55 milliseconds, while the 'e' is typed after 75. Since these are within 20 milliseconds of each other, they may be swapped.
"TH EPROBLEM"
{5,46,55,99,101,130,453,531,692,780,1003}
{"the","problem"}
Returns: "TH EPROBLEM"
Here the 'E' is typed 44 milliseconds after the space and hence may not be swapped.
"TH Eproblem"
{5,46,55,59,101,130,453,531,692,780,1003}
{"the","problem","th","eproblem"}
Returns: "TH Eproblem"
Though the 'E' and the space are typed within 20 milliseconds of each other, both "th" and "eproblem" are in the dictionary, so no swap occurs.
"onc eupo n atime"
{10,20,30,40,50,60,70,80,90,100,
110,120,130,140,150,160}
{"once","upon","a","time"}
Returns: "onc eupo n atime"
Note that if we applied the transformation at all of the spaces, we would end up with 4 valid words, but our algorithm only does one pair at a time, and hence can do nothing here.
"Th eQuic kBrown Fox JUMPE Dover"
{10,20,30,40,50,60,70,80,90,100,
110,120,130,140,150,160,170,180,
280,380,480,580,680,780,880,980,
1080,1180,1280,1380,1480}
{"the","quick","brown","fox","quic","jumped","over","ox","jump"}
Returns: "The Quick Brown Fox JUMPE Dover"
Originally, we can't swap the space and the 'k' to form "eQuick", because that is not in the dictionary. However, since we are working from left to right, and changing the sentence as we go, we move the 'e' to form "The", (as "quic" is in the dictionary) and then when we look at the 'k', we are allowed to move it.
"a bbb aab a b"
{1,2,3,4,5,6,7,8,9,10,11,12,13}
{"ab","bba","bbba"}
Returns: "a bbba ab a b"
Notice that, after we apply the transformation between the second and third words, if we started over we would apply the transformation between the first and second words. However, we are applying transformations in one pass, from left to right, so we don't go back and do this.
Submissions are judged against all 59 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AutoFix with a public method string fix(string sentence, vector<int> times, vector<string> dictionary) · 59 test cases · 2 s / 256 MB per case