Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WeddingPresents {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int guests = Integer.parseInt(sc.nextLine());
- int gifts = Integer.parseInt(sc.nextLine());
- int moneyGifts = 0; // A
- int urediGifts = 0; // B
- int vaucheriGifts = 0; // V
- int otherGifts = 0; // G
- for (int i = 1; i <= gifts; i++) {
- String input = sc.nextLine();
- if (input.equals("A")) {
- moneyGifts++;
- } else if (input.equals("B")) {
- urediGifts++;
- } else if (input.equals("V")) {
- vaucheriGifts ++;
- } else if (input.equals("G")) {
- otherGifts++;
- }
- }
- double percentMoney = moneyGifts * 1.0 / gifts * 100;
- double percentUredi = urediGifts * 1.0 / gifts * 100;
- double percentVaucheri = vaucheriGifts * 1.0 / gifts * 100;
- double percentOthers = otherGifts * 1.0 / gifts * 100;
- double percentGuests = gifts * 1.0 / guests * 100;
- System.out.printf("%.2f%%\n%.2f%%\n%.2f%%\n%.2f%%\n%.2f%%", percentMoney, percentUredi, percentVaucheri, percentOthers, percentGuests);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement