Algorithm


Problem Name: beecrowd | 2523

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

Will's Message

 

By Ricardo Oliveira, UFPR BR Brazil

Timelimit: 1

After an intense match of a RPG game at the house of one of his friends, young Will disappeared mysteriously! Everyone is desperately looking for him everywhere. Meanwhile, strange things are happening at your home. One of these things, however, allows you to communicate with the boy!

There are exactly 26 bulbs attached to the wall of your living room, numbered from 1 to 26 from left to right. Also, there is a letter drawn in the wall bellow each bulb. When Will wants to send you a message, he will (mysteriously) blink the bulbs corresponding to each letter of his message, one at a time. For example, if he wants to send you the message HELP, he will blink, in this order, the bulbs above the letters H, E, L and P.

Given the letter associated to each bulb and the order of the bulbs Will blinked, decipher the message he sent!

 

Input

 

The input contains several test cases. The first line of each test case contains a string with exactly 26 uppercase letters, containing all letters of the English alphabet. The first letter in the string is associated to bulb 1; the second letter in the string is associated to bulb 2; and so on. The next line contains an integer N (1 ≤ N ≤ 104), the number of bulbs that were blinked. The third line contains N integers li (1 ≤ li ≤ 26), indicating the bulbs that were blinked, in that order.

The input ends with end-of-file (EOF).

 

Output

 

For each test case, print a single line containing the message sent by Will.

 

 

 

Input Sample Output Sample

ABCDEFGHIJKLMNOPQRSTUVWXYZ
4
8 5 12 16
QWERTYUIOPASDFGHJKLZXCVBNM
10
16 3 19 19 9 2 9 4 19 13

HELP
HELLOWORLD

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int i, j, n, x;
    char str[10000], str1[10000];

    while (scanf("%s %i", str, &x) != EOF)
    {

    int a[x];

    for (i = 0; i  <  x; ++i)
        scanf("%i", &a[i]);

    for (j = 0; j  <  x; ++j)
    {
        for (i = 0; str[i] != 0; ++i)
        {
            if (a[j]-1 == i)
            {
                if (j == x-1)
                    printf("%c\n", str[i]);

                else
                    printf("%c", str[i]);
            }
        }
    }
    }

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 8 5 12 16 QWERTYUIOPASDFGHJKLZXCVBNM 10 16 3 19 19 9 2 9 4 19 13

Output

x
+
cmd
HELP HELLOWORLD

#2 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>
using namespace std;

int main()
{
    char s[1001];
    int n,l;
    while(scanf("%s",s) != EOF){
        scanf("%d",&n);
        while(n--){
                scanf("%d",&l);
            printf("%c",s[l-1]);
        }
        printf("\n");
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 8 5 12 16 QWERTYUIOPASDFGHJKLZXCVBNM 10 16 3 19 19 9 2 9 4 19 13

Output

x
+
cmd
HELP HELLOWORLD

#3 Code Example with Javascript Programming

Code - Javascript Programming


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


function main() {
	const responses = []

	for (let index = 0; index  <  input.length; index += 3) {
		if (input[index] == "") break // EOFile Condition

		const searchableText = input[index]

		const chars = input[index + 2]
			.split(" ", Number.parseInt(input[index + 1]))
			.map((q) => searchableText[+q - 1])
			.join("")

		responses.push(chars)
	}

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

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 8 5 12 16 QWERTYUIOPASDFGHJKLZXCVBNM 10 16 3 19 19 9 2 9 4 19 13

Output

x
+
cmd
HELP HELLOWORLD

#4 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        e = str(input())
        n = int(input())
        f = [int(x) for x in str(input()).split()]
        for i in f:
            print(e[i - 1], end='')
        print()
    except EOFError: break
Copy The Code & Try With Live Editor

Input

x
+
cmd
ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 8 5 12 16 QWERTYUIOPASDFGHJKLZXCVBNM 10 16 3 19 19 9 2 9 4 19 13

Output

x
+
cmd
HELP HELLOWORLD
Advertisements

Demonstration


Previous
#2520 Beecrowd Online Judge Solution 2520 The Last Analógimôn Solution in C, C++, Java, Js and Python
Next
#2530 Beecrowd Online Judge Solution 2530 Cheating Solution in C, C++, Java, Js and Python