Under construction

Still being built. Things may change

In Braille

Interview

Time limit1sMemory limit128 MB

Summary
Translate a string of digits to Braille cells, or three lines of Braille cells back to digits, using the fixed digit-to-cell table.
Level

Easy3 of 10

Topics
String, Hash map, Implementation, Simulation
Solved
No attempts yet

Problem

The Braille system, designed by Louis Braille in 1825, transformed written communication for blind and visually impaired people. Braille, who was himself blind, devised a tactile writing system in which each symbol is a cell of six dot positions arranged in three rows and two columns. Every dot position is either raised or flat, giving 64 possible patterns that trained fingers can read.

You must build a Braille dictionary module that converts messages made up only of decimal digits to or from Braille. Each decimal digit corresponds to exactly one Braille cell, as shown below. A raised dot is written as *, a flat dot as ., and each cell is written as three rows of two characters:

digit  row1 row2 row3
  0     .*   **   ..
  1     *.   ..   ..
  2     *.   *.   ..
  3     **   ..   ..
  4     **   .*   ..
  5     *.   .*   ..
  6     **   *.   ..
  7     **   **   ..
  8     *.   **   ..
  9     .*   *.   ..

Given a message composed only of digits, translate it either to Braille or from Braille.

Input

The input contains several test cases. Each test case is given on three or five lines:

  • The first line contains an integer DD, the number of digits in the message (1≤D≤1001 \le D \le 100).
  • The second line contains a single uppercase letter, S or B.
    • If it is S, the next single line contains a message of DD decimal digits that you must translate to Braille.
    • If it is B, the next three lines contain a message of DD Braille cells that you must translate from Braille. On each line the cells are separated by single spaces; within a cell a raised position is * and a flat position is ..

The input ends with a line containing a single zero, which is not a test case.

Output

For each test case, print the translated message in the same format as the input:

  • If the test case was S (digits to Braille), print the DD Braille cells on three lines, with cells separated by single spaces.
  • If the test case was B (Braille to digits), print the DD decimal digits on a single line.

Examples1

  1. Example 1

    Input
    10
    S
    1234567890
    3
    B
    *. *. **
    .. *. ..
    .. .. ..
    2
    S
    00
    0
    
    Expected output
    *. *. ** ** *. ** ** *. .* .*
    .. *. .. .* .* *. ** ** *. **
    .. .. .. .. .. .. .. .. .. ..
    123
    .* .*
    ** **
    .. ..