Advertisement
Stann

Untitled

May 26th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MagicCarNumbers {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int magicWeight = sc.nextInt();
  8.  
  9.         int[] letterValues = { 10, 20, 30, 50, 80, 110, 130, 160, 200, 240 };
  10.         int sum = 40;//CA
  11.         int result = 0;
  12.         int counter = 0;
  13.  
  14.         for (int i = 0; i < 9999; i++) {
  15.             int first = i / 1000 % 10;
  16.             int second = i / 100 % 10;
  17.             int third = i / 10 % 10;
  18.             int fourth = i % 10;
  19.             //first letter
  20.             for (int j = 0; j < letterValues.length; j++) {
  21.                 //second letter
  22.                 for (int j2 = 0; j2 < letterValues.length; j2++) {
  23.                     result = sum + first + second + third + fourth
  24.                             + letterValues[j] + letterValues[j2];
  25.                     boolean firstFormat = first == second && first == third
  26.                             && first == fourth;
  27.                     boolean secondFormat = second == third && second == fourth;
  28.                     boolean thirdFormat = first == second && first == third;
  29.                     boolean fourthFormat = first == second && third == fourth;
  30.                     boolean fifthFormat = first == third && second == fourth;
  31.                     boolean sixthFormat = first == fourth && second == third;
  32.                     if ((result == magicWeight)
  33.                             && (firstFormat == true || secondFormat == true
  34.                                     || thirdFormat == true
  35.                                     || fourthFormat == true
  36.                                     || fifthFormat == true || sixthFormat == true)) {
  37.                         counter++;
  38.  
  39.                     }
  40.                 }
  41.  
  42.             }
  43.  
  44.         }
  45.         System.out.println(counter);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement