BRAILLE - Braille Transcription

no tags 

Visually handicapped people use Braille system of codes for reading and writing. The basic Braille symbol (or cell) is composed of six dots arranged in two vertical columns, each column being three dots high. This pattern produces 64 one-cell symbols with character index #(20a1 + 21a2 + 22a3 + 23a4 + 24a5 + 25a6), where ai = 1, if dot i is embossed up and zero otherwise. The positions of these dots are numbered as follows:

A cell without numbers A cell with numbers


Many Braille codes are in use; one such is the Simple Braille System (SBS). In SBS alphabets in lower case are default characters; letters `a, b,..., z' have character indices `1, 2, ..., 26' respectively. The ``letter sign'' (dots 5-6) may be used optionally before a string of alphabets in lower case. Each numeric digit 0-9 requires one cell, with character index the digit itself. However the ``number sign'' (dots 3-4-5-6) is added before a string of numerals. In order to revert back to normal alphabets after a string of numerals, the ``letter sign'' is used. The blank cell is used as a space in alphabetic context and zero in numeric context. For example the numerals 1 - 10 are the same as the first ten letters of the alphabet, index of #a being 1 and #j being 10. SBS allows the contraction of `th', by a single cell with dots 1-4-5-6. A two-cell contraction for `tion' is allowed with dots 5-6 and dots 1-3-4-5.

There are no single-cell codes for capital letters in SBS. So a ``capital sign'' (dot 6) is inserted before a capital letter. Two ``capital signs'' are inserted to indicate that the string of alphabets that follows is capitalized. To revert back to normal alphabets (or numerals), the ``letter sign'' (or the ``number sign'') is used. SBS ignores punctuation marks altogether.

You are required to write a program for SBS transcription that converts an SBS code to English.


Input consists of multiple test cases.

In each test case there is an SBS code. It is given in three input lines containing a certain number of Braille cells. Each Braille cell is represented by a 3×2 array of 0's and 1's, appearing in an odd and the next even numbered column of the three input lines, where `1' is used for an embossed dot and `0' otherwise.

A line that is not a part of an SBS code, containing a single zero in column 1 terminates input.


For each test case, output the SBS code in English, in one line. In case the input does not conform to SBS rules stated above output simply the sign `?'.

Sample Input 


Sample Output 


Kanpur-Kolkata 2004-2005

hide comments
Simes: 2013-08-11 21:20:35

Moved to the forum.

Last edit: 2017-09-01 19:26:22
Shashi Kant Prasad: 2013-04-23 10:18:10

Last edit: 2013-08-11 05:00:33
Hagen von Eitzen: 2011-07-09 12:09:54

The problem formulation contradicts itself:
"For example the numerals 1 - 10 are the same as the first ten letters of the alphabet, index of #a being 1 and #j being 10." is not an *example* of what is written before.
Instead, it directly *contradicts* the previous statement "Each numeric digit 0-9 requires one cell, with character index the digit itself."
as the latter implies that "10" MUST be encoded as #a_ and not as #j.

So what is correct? Does (in number mode) #j translate to "10" or is it illegal? Should we infer that #z translates to "26"? And are #ja, #aj, #jj valid encodings of "101", "110", "1010", respectivly?

Hagen von Eitzen: 2011-07-08 21:14:31

Is there no bound on line length?

Ilya Seleznev: 2010-09-10 04:22:19

judge also uses capital sign to switch from "digit mode" to "letter mode". Beware!

Ilya Seleznev: 2010-09-08 12:02:11

What I should output, if no printable character is decoded? For example if input have only (number_sign, number_sign) etc?

Tony Beta Lambda: 2010-03-10 13:14:39

Use scanf() instead of gets().

Added by:Duc
Time limit:0.166s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ACM Kanpur 2004