AsyaDamyanova

Golf

Dec 2nd, 2019
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Golf {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int record = Integer.parseInt(scanner.nextLine());
  7.         int halls = Integer.parseInt(scanner.nextLine());
  8.         int counter = 0;
  9.  
  10.         for (int i = 1; i <= halls; i++) {
  11.             int strength = Integer.parseInt(scanner.nextLine());
  12.             int memoryGoal = 0;
  13.             while (!(memoryGoal >= strength)) {
  14.                 counter++;
  15.                 int goal = 0;
  16.                 String text = scanner.nextLine();
  17.                 for (int k = 0; k < text.length(); k++) {
  18.                     goal += text.charAt(k);
  19.                 }
  20.                 goal /= text.length();
  21.                 memoryGoal += goal;
  22.                 goal = 0;
  23.  
  24.             }
  25.             System.out.printf("New hole reached! Hits so far: %d%n", counter);
  26.         }
  27.  
  28.         if (counter < record) {
  29.             System.out.printf("Yes, you won! Total hits: %d", counter);
  30.         } else {
  31.             System.out.printf("Better luck next time... Total hits: %d", counter);
  32.         }
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment