URI Online Judge Solution 1049 Animal – Solution in C, C++, Java, Python and C#

URI Online Judge Solution URI Solution -Beginner

URI Online Judge Solution 1049 Animal – Solution in C, C++, Java, Python and C#

URI Online Judge Solution 1049 Animal | Beginner
URI Problem Link – https://www.urionlinejudge.com.br/judge/en/problems/view/1049

Problem Name: 1049 Animal Solution
Problem Number : URI – 1049 Animal Code
Online Judge : URI Online Judge Solution
Category: Beginner
Solution Language : C,C plus plus, java, python, c#(c sharp)

URI Online Judge Solution 1049 Animal - Solution in C, C++, Java, Python and C#

URI 1049 Animal Code in C / URI 1049 solution in C:

#include <stdio.h>
#include <string.h>
int main()
{

char
c1[]="vertebrado", c11[22]="ave", c12[]="mamifero";
char
c111[]="carnivoro", c112[]="onivoro", c124[]="herbivoro";
char
a1[]="aguia", a2[]="pomba", a3[]="homem", a4[]="vaca";
char
c2[]="invertebrado", c21[]="inseto", c22[]="anelideo";
char
c211[]="hematofago", a5[]="pulga", a6[]="lagarta";
char
a7[]="sanguessuga", a8[]="minhoca";
char
a[22], b[22], c[22];
scanf("%s", a);
if
(0==strcmp(a,c1))
{

scanf("%s",b);
if
(0==strcmp(b,c11))
{

scanf("%s",c);
if
(0==strcmp(c,c111))
printf("%sn",a1);
else if
(0==strcmp(c,c112))
printf("%sn",a2);
}

if
(0==strcmp(b,c12))
{

scanf("%s",&c);
if
(0==strcmp(c,c112))
printf("%sn",a3);
else if
(0==strcmp(c,c124))
printf("%sn",a4);
}
}

else if
(0==strcmp(a,c2))
{

scanf("%s",b);
if
(0==strcmp(b,c21))
{

scanf("%s",&c);
if
(0==strcmp(c,c211))
printf("%sn",a5);
else if
(0==strcmp(c,c124))
printf("%sn",a6);
}

if
(0==strcmp(b,c22))
{

scanf("%s",&c);
if
(0==strcmp(c,c211))
printf("%sn",a7);
else if
(0==strcmp(c,c112))
printf("%sn",a8);
}
}

return
0;
}

URI 1049 Animal Code in C++ / URI 1049 solution in CPP:

#include <iostream>
#include <cstring>

using namespace
std;

int
main()
{

string c;

cin >> c;

if
(c == "vertebrado"){

cin >> c;
if
(c == "ave"){

cin >> c;
if
(c == "carnivoro"){
cout << "aguia" << endl;
}
else{
cout << "pomba" << endl;
}
}
else{

cin >> c;
if
(c == "onivoro"){
cout << "homem" << endl;
}
else{
cout << "vaca" << endl;
}
}
}
else{

cin >> c;
if
(c == "inseto"){

cin >> c;
if
(c == "hematofago"){
cout << "pulga" << endl;
}
else{
cout << "lagarta" << endl;
}
}
else{

cin >> c;
if
(c == "hematofago"){
cout << "sanguessuga" << endl;
}
else{
cout << "minhoca" << endl;
}
}
}

return
0;
}

URI 1049 Animal Code in java/ URI 1049 solution in Java:

import java.io.IOException;
import java.util.Scanner;

public class
Main {

public static
void main(String[] args) throws IOException {

String A, B, C;
Scanner input =new Scanner(System.in);
A = input.next();
B = input.next();
C = input.next();

if
(A.equals("vertebrado") && B.equals("ave") && C.equals("carnivoro")) {
System.out.print("aguian");
}

if
(A.equals("vertebrado") && B.equals("ave") && C.equals("onivoro")) {
System.out.print("pomban");
}

if
(A.equals("vertebrado") && B.equals("mamifero") && C.equals("onivoro")) {
System.out.print("homemn");
}

if
(A.equals("vertebrado") && B.equals("mamifero") && C.equals("herbivoro")) {
System.out.print("vacan");
}

//-----------------------------------------------------------------

if
(A.equals("invertebrado") && B.equals("inseto") && C.equals("hematofago")) {
System.out.print("pulgan");
}

if
(A.equals("invertebrado") && B.equals("inseto") && C.equals("herbivoro")) {
System.out.print("lagartan");
}

if
(A.equals("invertebrado") && B.equals("anelideo") && C.equals("hematofago")) {
System.out.print("sanguessugan");
}

if
(A.equals("invertebrado") && B.equals("anelideo") && C.equals("onivoro")) {
System.out.print("minhocan");
}

}

}

URI 1049 Animal Code in Python / URI 1049 solution in Python:

ent1 = raw_input()
ent2 = raw_input()
ent3 = raw_input()

if
(ent1 == "vertebrado"):
if
(ent2 == "ave"):
if
(ent3 == "carnivoro"):
print "aguia"
else
:
print "pomba"
else
:
if
(ent3 == "onivoro"):
print "homem"
else
:
print "vaca"
else
:
if
(ent2 == "inseto"):
if
(ent3 == "hematofago"):
print "pulga"
else
:
print "lagarta"
else
:
if
(ent3 == "hematofago"):
print "sanguessuga"
else
:
print "minhoca"

URI Solution 1049 Animal Code / URI 1049 solution in  C# (C Sharp):

Demonstration:

It’s only a work of string comparison, if you know the string comparison functions in any language, then you can solve this problem very easily.

In C, to compare a string,
first include #include <string.h>
Then, to check any string[that is actually compare to other string] function is strcmp() and it’s use in this line,

strcmp(a,c1)

– Which check the a string to c1 string if they match then they will return more than 0.

In java,

String A,
A.equals("new");

That means equals function of java can check any string easily and then you can solve the problem.

Just implement this in coding. Since having any problem just put a comment below. Thanks

Tags: URI Online Judge Solution, URI OJ Solution list, URI Problems Solution, URI solver, URI all problem solution list, URI 1049 Animal code in C, URI 1049 code in C++, URI 1049 Animal solution in C, URI solution, URI 1049 Animal solution in C, URI 1049 solution in C++-CPP,URI 1049 solution in C# (C sharp),URI 1049 solution in Java,URI 1049 Animal solution in Python,
URI Animal problem solution, URI 1049 problem solution

Leave a Reply

Your email address will not be published.