Algorithm
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1049
Animal
By Neilor Tonin, URI Brazil
In this problem, your job is to read three Portuguese words. These words define an animal according to the table below, from left to right. After, print the chosen animal defined by these three words.
Input
The input contains 3 words, one by line, that will be used to identify the animal, according to the above table, with all letters in lowercase.
Output
Print the animal name according to the given input.
Input Samples | Output Samples |
vertebrado |
homem |
vertebrado |
aguia |
invertebrado |
minhoca |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
char a[22], b[22], c[22];
cin>> a;
if(strcmp(a, "vertebrado") == 0){
cin>>b;
if(strcmp(b, "ave") == 0){
cin>>c;
if(strcmp(c, "carnivoro") == 0)
cout << "aguia" << endl;
else if(strcmp(c, "onivoro") == 0)
cout << "pomba" << endl;
}
if(strcmp(b, "mamifero") == 0){
cin>>c;
if(strcmp(c, "onivoro") == 0)
cout << "homem" << endl;
else if(strcmp(c, "herbivoro") == 0)
cout << "vaca" << endl;
}
}
else if(strcmp(a, "invertebrado") == 0){
cin>>b;
if(strcmp(b, "inseto") == 0){
cin>>c;
if(strcmp(c, "hematofago") == 0)
cout << "pulga" << endl;
else if(strcmp(c, "herbivoro") == 0)
cout << "lagarta" << endl;
}
if(strcmp(b, "anelideo") == 0){
cin>>c;
if(strcmp(c, "hematofago") == 0)
cout << "sanguessuga" << endl;
else if(strcmp(c, "onivoro") == 0)
cout << "minhoca" << endl;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.io.IOException;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
String a = input.nextLine();
if(a.equals("vertebrado")){
String b = input.nextLine();
if(b.equals("ave")){
String c = input.nextLine();
if(c.equals("carnivoro"))
System.out.println("aguia");
else if(c.equals("onivoro"))
System.out.println("pomba");
}
if(b.equals("mamifero")){
String c = input.nextLine();
if(c.equals("onivoro"))
System.out.println("homem");
else if(c.equals("herbivoro"))
System.out.println("vaca");
}
}
else if(a.equals("invertebrado")){
String b = input.nextLine();
if(b.equals("inseto")){
String c = input.nextLine();
if(c.equals("hematofago"))
System.out.println("pulga");
else if(c.equals("herbivoro"))
System.out.println("lagarta");
}
if(b.equals("anelideo")){
String c = input.nextLine();
if(c.equals("hematofago"))
System.out.println("sanguessuga");
else if(c.equals("onivoro"))
System.out.println("minhoca");
}
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var a = lines.shift()
if(a === "vertebrado"){
var b = lines.shift()
if(b === "ave"){
var c = lines.shift()
if(c === "carnivoro"){
console.log("aguia");
}
else if(c === "onivoro"){
console.log("pomba");
}
}
if(b === "mamifero"){
var c = lines.shift()
if(c === "onivoro"){
console.log("homem");
}
else if(c === "herbivoro"){
console.log("vaca");
}
}
}
else if(a === "invertebrado"){
var b = lines.shift()
if(b === "inseto"){
var c = lines.shift()
if(c === "hematofago"){
console.log("pulga");
}
else if(c === "herbivoro"){
console.log("lagarta");
}
}
if(b === "anelideo"){
var c = lines.shift()
if(c === "hematofago"){
console.log("sanguessuga");
}
else if(c === "onivoro"){
console.log("minhoca");
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
a = input()
if a == "vertebrado":
b = input()
if b =="ave":
c = input()
if c =="carnivoro":
print("aguia")
elif c == "onivoro":
print("pomba")
elif b == "mamifero":
c = input()
if c == "onivoro":
print("homem")
elif c == "herbivoro":
print("vaca")
elif a == "invertebrado":
b = input()
if b == "inseto":
c = input()
if c == "hematofago":
print("pulga")
elif c == "herbivoro":
print("lagarta")
elif b == "anelideo":
c = input()
if c == "hematofago":
print("sanguessuga")
elif c == "onivoro":
print("minhoca")
Copy The Code &
Try With Live Editor
Input
Output