Hidden Roman Numerals
Time limit1sMemory limit1024 MB
Find which of the twelve Roman numerals from 1 to 12 appear as substrings of a given string over {I,V,X}.
- Level
Easy2 of 10
- Topics
- String, Implementation, Brute force
- Solved
- No attempts yet
Problem
Bronius is learning the Roman numerals from 1 to 12. These numbers can be written using only three symbols — I, V, and X — as follows:
For practice, Bronius wrote on the board a random string of length made up of the symbols I, V, and X. He then looks for the Roman numerals from 1 to 12 that are hidden in the string. A number is hidden in the string if its Roman representation appears as a contiguous substring. For example, the string XIIIX hides the numbers 1, 2, 3, 9, 10, 11, 12.
Find all numbers from 1 to 12 that are hidden in the string Bronius wrote.
Input
The first line contains a positive integer , the length of the string.
The second line contains the symbols with no spaces. Each symbol is one of I, V, or X.
Output
Print, on a single line, all numbers hidden in the string in increasing order, separated by spaces.