How Was Typesetting Done in the Past?
Time limit1sMemory limit128 MB
Simulate historical typesetting rules by replacing letter combinations with ligature codes and correctly choosing long s versus short s per word based on multiple context-dependent rules.
- Level
Medium7 of 10
- Topics
- String, Implementation, Simulation
- Solved
- No attempts yet
Problem
Before digital typesetting, setting type was a craft that only skilled workers could perform. To save space and make printed text more beautiful, certain combinations of letters were printed as a single character called a ligature. For example, the a-e ligature is 'æ', and the f-i ligature is 'fi'. The possible ligatures and their output codes are listed in the hint table.
There were also two ways to print a lowercase s: "long s" and "short s". Today only the short s form is used. Decide which form to use by the following rules.
- An s at the end of a word, or an s immediately before punctuation inside a word such as a hyphen (-) or apostrophe (`), is a short s.
- For instance: programs, ſucceſs, hocus-pocus, revis'd
- An s immediately before f, b, or k is a short s.
- For instance: transfer, husband, ask, ſucceſsful
- If a word ending in ss is joined with a word beginning in s, so that the combined word contains sss, the middle s is short and the other s characters are long.
- For instance: croſsſtitch, croſsſtaff
- Every other s is a long s.
In this problem, a "word" is not the same as an "identifier". An identifier may contain punctuation such as _ or $, but a word is a consecutive run of letters only. Therefore identifiers such as radius3 and adios_amigo are typeset as radius3 and adios_amigo, not as radiuſ3 or adioſ_amigo.
Input
The first line contains the number of test strings P (1 <= P <= 1000).
Each of the next P lines contains one string of length at most 1000. The string contains only uppercase letters, lowercase letters, digits, spaces, and the special characters .,"'$;:?()-<>=!.
Output
For each test string, output the string after replacing each applicable letter sequence with the proper ligature or long s code. A short s remains s. Output AE and Ae as [AE], OE and Oe as [OE], and output ae and oe as [ae] and [oe]. Use the hint table for the other combinations.
Hint
Long s and short s may be mixed. For example, crossstitch becomes cro[longs]s[longst]itch. cro[longs]s[longs]titch is not correct.