Algorithm


Problem Name: beecrowd | 2850

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

Polyglot Parrot

 

By Felipe C. Ochial, URI BR Brazil

Timelimit: 1

Humberto has a smart parrot. When he has both legs on the ground, the parrot speaks Portuguese. When he lifts his left leg, he speaks in English. Finally, when he raises his right, he speaks French. Nico, Humberto's friend, was fascinated by the animal. In his excitement he asked, "And when he lift both of them?" Before Humberto could respond, the parrot shouted, "Oh, I'll fall, you idiot!"

 

Input

 

The input consists of several test cases. Each test case consists of a string informing the parrot's leg raising situation. “direita” means his right leg is raised, “esquerda” means his left leg is raised, “nenhuma” means none of his leg are raised and “as duas” means both his legs are raised.

 

Output

 

For each parrot's leg raising condition, print out the language he will use. For English, print “ingles”, for French print “frances” and for Portuguese print “portugues”. If he lifts both legs, print "caiu." Break a line for each test case.

 

 

 

Input Sample Output Sample

esquerda

direita

nenhuma

as duas

ingles

frances

portugues

caiu

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
#include <string.h>

int main ()
{

	char pergunta[10];

	while (scanf(" %[^\n]", pergunta) != EOF)
	{

		if (strcmp(pergunta, "esquerda") == 0)
			printf("ingles\n");
		else if (strcmp(pergunta, "direita") == 0)
			printf("frances\n");
		else if (strcmp(pergunta, "nenhuma") == 0)
			printf("portugues\n");
		else if (strcmp(pergunta, "as duas") == 0)
			printf("caiu\n");

	}

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
esquerda direita nenhuma as duas

Output

x
+
cmd
ingles frances portugues caiu

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    while (getline(cin, s))
    {
        if (s=="direita")
            cout << "frances" << endl;
        else if (s=="esquerda")
            cout << "ingles" << endl;
        else if (s=="nenhuma")
            cout << "portugues" << endl;
        else if (s=="as duas")
            cout << "caiu" << endl;
        fflush(stdin);
    }
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
esquerda direita nenhuma as duas

Output

x
+
cmd
ingles frances portugues caiu

#3 Code Example with Javascript Programming

Code - Javascript Programming


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

const ParrotLegsStateEnum = {
	"esquerda": "ingles",
	"direita": "frances",
	"nenhuma": "portugues",
	"as duas": "caiu"
}

const output = []

while (input.length > 0) {
	const state = input.shift()
	if (state == "") break // EOFile Condition

	output.push(ParrotLegsStateEnum[state])
}

console.log(output.join("\n"))
Copy The Code & Try With Live Editor

Input

x
+
cmd
esquerda direita nenhuma as duas

Output

x
+
cmd
ingles frances portugues caiu

#4 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        c = input()
        if c == 'esquerda':
            print('ingles')
        elif c == 'direita':
            print('frances')
        elif c == 'nenhuma':
            print('portugues')
        elif c == 'as duas':
            print('caiu')

    except EOFError:
        break

Copy The Code & Try With Live Editor

Input

x
+
cmd
esquerda direita nenhuma as duas

Output

x
+
cmd
ingles frances portugues caiu
Advertisements

Demonstration


Previous
#2846 Beecrowd Online Judge Solution 2846 Fibonot Solution in C, C++, Java, Js and Python
Next
#2852 Beecrowd Online Judge Solution 2852 Messaging Solution in C, C++, Java, Js and Python