georgimanov

MagicCarNumbers

May 26th, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class MagicCarNumbers {
  3.  
  4.     public static void main(String[] args) {
  5.        
  6.         Scanner scanner = new Scanner(System.in);
  7.         long magicWeight = scanner.nextLong();
  8.         long sum = 40;
  9.         int counter = 0;
  10.         int[] weight = {10, 20, 30, 50, 80, 110, 130, 160, 200, 240};
  11.         for (int i1 = 0; i1 <= 9; i1++) {
  12.             for (int i2 = 0; i2 <= 9; i2++) {
  13.                 for (int i3 = 0 ; i3 <= 9; i3++) {
  14.                     for (int i4 = 0 ; i4 <= 9; i4++) {
  15.                         for (int i5 = 0; i5 < weight.length; i5++) {
  16.                             for (int i6 = 0; i6 < weight.length; i6++) {
  17.                                 sum += + i1 + i2 + i3 + i4 + weight[i5] + weight[i6];
  18.                                 if (magicWeight == sum) {
  19.                                     if(i1 == i2 && i2 == i3 && i3 == i4 ) { counter ++;}      //aaaa
  20.                                     else if ( i1 != i2 && i2 == i3 && i3 == i4) { counter++;} //abbb
  21.                                     else if ( i1 == i2 && i2 == i3 && i3 != i4) { counter++;} //aaab
  22.                                     else if ( i1 == i2 && i2 != i3 && i3 == i4) { counter++;} //aabb
  23.                                     else if ( i1 == i3 && i1 != i2 && i2 == i4) { counter++;} //abab
  24.                                     else if ( i1 == i4 && i1 != i2 && i2 == i3) { counter++;} //abba
  25.                                 }
  26.                                 sum = 40;
  27.                             }
  28.                         }
  29.                     }
  30.                 }
  31.             }
  32.         }
  33.         System.out.println(counter);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment