(URI) Experiências - Solução
import java.io.*;
import java.util.*;
class Main {
public static void process() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
String animals = "CRS";
int[] results = new int[4];
int numTests = sc.nextInt();
for (int i = 0; i < numTests; i++) {
int qty = sc.nextInt();
String op = sc.next();
results[animals.indexOf(op)] += qty;
results[3] += qty;
}
System.out.println("Total: " + results[3] + " cobaias");
System.out.println("Total de coelhos: " + results[0]);
System.out.println("Total de ratos: " + results[1]);
System.out.println("Total de sapos: " + results[2]);
System.out.println("Percentual de coelhos: " + String.format("%.2f", (double)results[0]/results[3]*100) + " %");
System.out.println("Percentual de ratos: " + String.format("%.2f", (double)results[1]/results[3]*100) + " %");
System.out.println("Percentual de sapos: " + String.format("%.2f", (double)results[2]/results[3]*100) + " %");
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
import java.util.*;
class Main {
public static void process() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
String animals = "CRS";
int[] results = new int[4];
int numTests = sc.nextInt();
for (int i = 0; i < numTests; i++) {
int qty = sc.nextInt();
String op = sc.next();
results[animals.indexOf(op)] += qty;
results[3] += qty;
}
System.out.println("Total: " + results[3] + " cobaias");
System.out.println("Total de coelhos: " + results[0]);
System.out.println("Total de ratos: " + results[1]);
System.out.println("Total de sapos: " + results[2]);
System.out.println("Percentual de coelhos: " + String.format("%.2f", (double)results[0]/results[3]*100) + " %");
System.out.println("Percentual de ratos: " + String.format("%.2f", (double)results[1]/results[3]*100) + " %");
System.out.println("Percentual de sapos: " + String.format("%.2f", (double)results[2]/results[3]*100) + " %");
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
Comments
Post a Comment