Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MagicCarNumbers {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int magicWeight = sc.nextInt();
- int[] letterValues = { 10, 20, 30, 50, 80, 110, 130, 160, 200, 240 };
- int sum = 40;//CA
- int result = 0;
- int counter = 0;
- for (int i = 0; i < 9999; i++) {
- int first = i / 1000 % 10;
- int second = i / 100 % 10;
- int third = i / 10 % 10;
- int fourth = i % 10;
- //first letter
- for (int j = 0; j < letterValues.length; j++) {
- //second letter
- for (int j2 = 0; j2 < letterValues.length; j2++) {
- result = sum + first + second + third + fourth
- + letterValues[j] + letterValues[j2];
- boolean firstFormat = first == second && first == third
- && first == fourth;
- boolean secondFormat = second == third && second == fourth;
- boolean thirdFormat = first == second && first == third;
- boolean fourthFormat = first == second && third == fourth;
- boolean fifthFormat = first == third && second == fourth;
- boolean sixthFormat = first == fourth && second == third;
- if ((result == magicWeight)
- && (firstFormat == true || secondFormat == true
- || thirdFormat == true
- || fourthFormat == true
- || fifthFormat == true || sixthFormat == true)) {
- counter++;
- }
- }
- }
- }
- System.out.println(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement