Sunday, May 1, 2016

URI Online Judge Solution 1094 Experiments

https://www.urionlinejudge.com.br/judge/en/problems/view/1094



URI Online Judge | 1094

Experiments

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Maria has just started as graduate student in a medical school and she's needing your help to organize a laboratory experiment which she is responsible about. She wants to know, at the end of the year, how many animals were used in this laboratory and the percentage of each type of animal is used at all.
This laboratory uses in particular three types of animals: frogs, rats and rabbits. To obtain this information, it knows exactly the number of experiments that were performed, the type and quantity of each animal is used in each experiment.

Input

The first line of input contains an integer N indicating the number of test cases that follows. Each test case contains an integer Amount (1 ≤ Amount ≤ 15) which represents the amount of animal used and a characterType ('C', 'R' or 'S'), indicating the type of animal:
CCoelho (rabbit in portuguese)
RRato (rat  in portuguese)
SSapo (frog in portuguese)

Output

Print the total of animals used, the total of each type of animal and the percentual of each one in relation of the total of animals used. The percentual must be printed with 2 digits after the decimal point.
Input SampleOutput Sample
10
10 C
6 R
15 S
5 C
14 R
9 C
6 R
8 S
5 C
14 R
Total: 92 cobaias
Total de coelhos: 29
Total de ratos: 40
Total de sapos: 23
Percentual de coelhos: 31.52 %
Percentual de ratos: 43.48 %
Percentual de sapos: 25.00 %

URI Online Judge Solution 1094 in Java


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

public class Main {

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

        int N, X, total = 0, total_C = 0, total_R = 0, total_S = 0;
float total_C_parcent = 0,total_R_parcent = 0, total_S_parcent = 0;
String animal_cha;
Scanner input =new Scanner(System.in);
N = input.nextInt();
for (int i = 1; i <= N; i++) {
X = input.nextInt();
animal_cha =input.next();
total += X;
if (animal_cha.equals("C")) {
total_C += X;
}else if(animal_cha.equals("R")){
total_R += X;
}else if(animal_cha.equals("S")){
total_S += X;
}
total_C_parcent = (float)((total_C * 100.00) /total);
total_R_parcent = (float)((total_R * 100.00) /total);
total_S_parcent = (float)((total_S * 100.00) /total);

}

System.out.print("Total: "+total+" cobaias\n");
System.out.print("Total de coelhos: "+total_C+"\n");
System.out.print("Total de ratos: "+total_R+"\n");
System.out.print("Total de sapos: "+total_S+"\n");

System.out.printf("Percentual de coelhos: %.2f",total_C_parcent);
System.out.print(" %\n");
System.out.printf("Percentual de ratos: %.2f",total_R_parcent);
System.out.print(" %\n");
System.out.printf("Percentual de sapos: %.2f",total_S_parcent);
System.out.print(" %\n");

    }

}






No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.