Advertisement
vpaleshnikov

ControlNumber

Apr 26th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem06_ControlNumber {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int m = Integer.parseInt(scanner.nextLine());
  8.         int controlNum = Integer.parseInt(scanner.nextLine());
  9.         int sum = 0;
  10.         int moveCounter = 0;
  11.  
  12.         for (int i = 1; i <= n ; i++) {
  13.             for (int j = m; j >= 1 ; j--) {
  14.                 sum = sum + (i * 2 + j * 3);
  15.                 moveCounter++;
  16.  
  17.                 if (sum >= controlNum) {
  18.                     break;
  19.                 }
  20.             }
  21.         }
  22.         if (sum >= controlNum) {
  23.             System.out.println(moveCounter + " moves");
  24.             System.out.printf("Score: %d >= %d%n", sum, controlNum);
  25.         } else {
  26.             System.out.println(moveCounter + " moves");
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement