Algorithm


Problem Name: beecrowd | 2727

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2727

Secret Code

 

By Juliane Alves, UFRGS BR Brazil

Timelimit: 1

Joana likes to play pretending to be a secret agent with her friends Bruna, Jaqueline and Laura. Joana and Bruna have created a secret code to communicate without their enemies discovering their plans. The secret code works as follows:

  • The letter 'a' is represented by a single dot '.'
  • The letter 'b' is represented by two dots '..'
  • The letter 'c' is represented by three dots '...'
  • The other letters follow the previous logic, however each set of points is separated by a space and always with a set of more points, as in the example below:

. → a
.. → b

... → c

. . → d

.. .. → e
... ... → f

. . . → g
.. .. .. → h
... ... ... → i

Your goal is to create a program that decipher the secret messages and help Jaqueline and Laura find out what Joana and Bruna are planning.

 

Input

 

The input contains several test cases. The first line of each test should contain an integer (≤ 50), which represents the number of letters to be deciphered and the next N lines contain the code for each letter.

 

Output

 

A string represented by the letter of the alphabet corresponding to the input code. Each string must be separated from the other by a new line.

 

 

 

Input Sample Output Sample

2
... ... ... ... ...
... ... ...
3
... ... ... ... ...
... ... ... ...
.

o
i
o
l
a

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    string str;
    while (cin >> n)
    {
        getline(cin, str);
        while (n--)
        {
            getline(cin, str);
            bool flag=true;
            int s=0, d=0, x;
            char c;
            for (int j = 0; j  <  str.size(); ++j)
            {
                if (str[j]==' ')
                {
                    s++;
                    flag=false;
                }
                if (flag)
                    d++;
            }
            x=(3*s)+(d-1);
            c=x+'a';
            printf("%c\n", c);
        }
    }
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
2 ... ... ... ... ... ... ... ... 3 ... ... ... ... ... ... ... ... ... .

Output

x
+
cmd
o i o l a

#2 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()) {
			int n = Integer.parseInt(sc.nextLine());
			String[] cod = new String[n];
			for (int x = 0 ; x  <  n ; x++)
				cod[x] = sc.nextLine();
			for (int x = 0 ; x  <  n ; x++) {
				if(cod[x].equals(".")) System.out.println("a");
				if(cod[x].equals("..")) System.out.println("b");
				if(cod[x].equals("...")) System.out.println("c");
				if(cod[x].equals(". .")) System.out.println("d");
				if(cod[x].equals(".. ..")) System.out.println("e");
				if(cod[x].equals("... ...")) System.out.println("f");
				if(cod[x].equals(". . .")) System.out.println("g");
				if(cod[x].equals(".. .. ..")) System.out.println("h");
				if(cod[x].equals("... ... ...")) System.out.println("i");
				if(cod[x].equals(". . . .")) System.out.println("j");
				if(cod[x].equals(".. .. .. ..")) System.out.println("k");
				if(cod[x].equals("... ... ... ...")) System.out.println("l");
				if(cod[x].equals(". . . . .")) System.out.println("m");
				if(cod[x].equals(".. .. .. .. ..")) System.out.println("n");
				if(cod[x].equals("... ... ... ... ...")) System.out.println("o");
				if(cod[x].equals(". . . . . .")) System.out.println("p");
				if(cod[x].equals(".. .. .. .. .. ..")) System.out.println("q");
				if(cod[x].equals("... ... ... ... ... ...")) System.out.println("r");
				if(cod[x].equals(". . . . . . .")) System.out.println("s");
				if(cod[x].equals(".. .. .. .. .. .. ..")) System.out.println("t");
				if(cod[x].equals("... ... ... ... ... ... ...")) System.out.println("u");
				if(cod[x].equals(". . . . . . . .")) System.out.println("v");
				if(cod[x].equals(".. .. .. .. .. .. .. ..")) System.out.println("w");
				if(cod[x].equals("... ... ... ... ... ... ... ...")) System.out.println("x");
				if(cod[x].equals(". . . . . . . . .")) System.out.println("y");
				if(cod[x].equals(".. .. .. .. .. .. .. .. ..")) System.out.println("z");

			}
		}
		sc.close();
	}

}

Copy The Code & Try With Live Editor

Input

x
+
cmd
2 ... ... ... ... ... ... ... ... 3 ... ... ... ... ... ... ... ... ... .

Output

x
+
cmd
o i o l a

#3 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("fs")
const input = readFileSync("/dev/stdin", "utf8").split("\n")

function getCharFromSequence(sequence = "") {
	const BASE = 96

	const splittedSeq = sequence.split(" ")
	const len = splittedSeq.length - 1

	const [point] = splittedSeq
	const index = BASE + point.length + len * 3

	return String.fromCharCode(index)
}

function main() {
	const responses = []

	while (input.length > 0) {
		const rows = Number.parseInt(input.shift())

		if (isNaN(rows)) break // EOFile Condition Verification

		const pointsSequences = input.splice(0, rows).map(getCharFromSequence)
		responses.push(...pointsSequences)
	}

	console.log(responses.join("\n"))
}

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 ... ... ... ... ... ... ... ... 3 ... ... ... ... ... ... ... ... ... .

Output

x
+
cmd
o i o l a

#4 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        alf = 'abcdefghijklmnopqrstuvwxyz'
        n = int(input())
        saida = ''
        while n > 0:
            l = input().split()
            pos = len(l[0]) + 3*(len(l)-1)
            saida += alf[pos-1]
            n -= 1
        for n in saida:
            print(n)
    except EOFError:
        break
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 ... ... ... ... ... ... ... ... 3 ... ... ... ... ... ... ... ... ... .

Output

x
+
cmd
o i o l a
Advertisements

Demonstration


Previous
#2724 Beecrowd Online Judge Solution 2724 Help Patatatitu Solution in C, C++, Java, Js and Python
Next
#2730 Beecrowd Online Judge Solution 2730 Paired Pairs Solution in C, C++, Java, Js and Python