printРабочее место участника

printЗадачи

217. Led Codes

Ограничения: время – 1s/2s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Some led systems display characters as a combination of lightlines, much like digital calculators do. Suppose we have one of such led systems, in which each letter of the standard English alphabet is constructed combining some of ten possible lightlines, numbered as below:
1326.gif
For instance, the letter A is shown using the lines 1,2,3,4,5 and 7. With these few lines it is not possible, of course, to show all the 26 letters with their natural shapes. A complete list of the letters of our system is appended at the end.
You have to solve the problem of decoding a combination of numbers (representing lightlines) in the form of the respective letter, to form a whole word or phrase. As input you have a string of letters and/or numbers, and as output you must show only the letters.
The input file begins with a line containing a single integer N, that indicates the number of input examples, followed by N lines, each one representing an input phrase. Each input phrase consists of lowercase and uppercase letters, blank spaces and/or digits. In the case of digits, their combination must form valid led letters. Each letter is coded as a combination of numbers, ordered in the form 1,2,3,4,5,6,7,8,9,0. A zero (0) that is not part of a valid letter code, is interpreted as a blank space. You may assume that no invalid codes are entered, and that the system does not allow ambiguity between two letter codes.
The output file consists of N lines (one for each input string) with the form:
Phrase 1: ..... 
Phrase 2: ..... 
where the dots are, of course, the result of the decoding process. The alphabetic letters and blank spaces must not be decoded at all: only the numbers must be converted to the corresponding led letters.

Sample Input

3 
HELL1235670WO1234591561580 
PROGRAMMING037124670C123567123567156 
and more037124903735790278134573712467045612356735792781245612467278 

Sample Output

Phrase 1: HELLO WORLD 
Phrase 2: PROGRAMMING IS COOL 
Phrase 3: and more IF IN THIS CONTEST
1327.gif
Source: ACM South America programming contest, 2000
loading