Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _4_MagicCarNumbers {
- private static char[] letters = { 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'P',
- 'T', 'X' };
- private static int[] weights = { 10, 20, 30, 50, 80, 110, 130, 160, 200,
- 240 };
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- int magicWeight = scan.nextInt();
- int countMagicCarNumbers = 0;
- if (magicWeight >= 60 && magicWeight <= 556) {
- magicWeight -= 40;
- countMagicCarNumbers = getCountOfMagicCarNumbers(magicWeight);
- }
- System.out.println(countMagicCarNumbers);
- }
- private static int getCountOfMagicCarNumbers(int magicWeight) {
- int counter = 0;
- int d1, d2, d3, d4, let1, let2;
- for (d1 = 0; d1 <= 9; d1++) {
- for (d2 = 0; d2 <= 9; d2++) {
- for (d3 = 0; d3 <= 9; d3++) {
- for (d4 = 0; d4 <= 9; d4++) {
- for (let1 = 0; let1 < letters.length; let1++) {
- for (let2 = 0; let2 < letters.length; let2++) {
- int specialWeight = calculateTheWeightOfSpecialMagicNumbers(
- d1, d2, d3, d4, let1, let2);
- if (specialWeight == magicWeight) {
- counter++;
- }
- }
- }
- }
- }
- }
- }
- return counter;
- }
- private static int calculateTheWeightOfSpecialMagicNumbers(int a, int b,
- int c, int d, int x, int y) {
- boolean numberIsSpecial = (b == a && c == a && d == a)
- || (b != a && c == b && d == b) || (b == a && c == a && d != a)
- || (b == a && c != a && d == c) || (b != a && c == a && d == b)
- || (b != a && c == b && d == a);
- int weight = 0;
- if (numberIsSpecial) {
- weight = a + b + c + d + weights[x] + weights[y];
- }
- return weight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement