Advertisement
Guest User

Magic Car Numbers

a guest
May 3rd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class Program
  9. {
  10.     static void Main(string[] args)
  11.     {
  12.         char[] letter = { 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'P', 'T', 'X' };
  13.         int[] weights = { 10, 20, 30, 50, 80, 110, 130, 160, 200, 240 };
  14.  
  15.         int inputSum = Int32.Parse(Console.ReadLine());
  16.         int weightOfCA = weights[Array.IndexOf(letter, 'C')] + weights[Array.IndexOf(letter, 'A')];
  17.         int counter = 0;
  18.         for (int firstDigit = 0; firstDigit < 10; firstDigit++)
  19.         {
  20.             for (int secondDigit = 0; secondDigit < 10; secondDigit++)
  21.             {
  22.                 for (int thirdDigit = 0; thirdDigit < 10; thirdDigit++)
  23.                 {
  24.                     for (int forthDigit = 0; forthDigit < 10; forthDigit++)
  25.                     {
  26.                         for (int firstLetter = 0; firstLetter < 10; firstLetter++)
  27.                         {
  28.                             char currLetter = letter[firstLetter];
  29.                             int currWeight = weights[firstLetter];
  30.                             for (int secondLetter = 0; secondLetter < 10; secondLetter++)
  31.                             {
  32.                                 char secondCurrLetter = letter[secondLetter];
  33.                                 int secondCurrWeight = weights[secondLetter];
  34.                                 // tuka lainata po4vat da se slu4vat , mamaudaiba
  35.                                 if (firstDigit == secondDigit && secondDigit == thirdDigit && thirdDigit == forthDigit ||
  36.                                     secondDigit == thirdDigit && thirdDigit == forthDigit && firstDigit != forthDigit ||
  37.                                     firstDigit == secondDigit && secondDigit == thirdDigit && forthDigit != thirdDigit ||
  38.                                     firstDigit == secondDigit && thirdDigit == forthDigit && forthDigit != firstDigit ||
  39.                                     firstDigit == thirdDigit && secondDigit == forthDigit && firstDigit != secondDigit ||
  40.                                     firstDigit == forthDigit && secondDigit == thirdDigit && firstDigit != secondDigit)
  41.                                 {
  42.  
  43.  
  44.                                     int sumOfCurrentSetOfCHars = weightOfCA + firstDigit + secondDigit + thirdDigit + forthDigit +
  45.                                         currWeight + secondCurrWeight;
  46.                                     if (sumOfCurrentSetOfCHars == inputSum)
  47.                                     {
  48.                                         counter++;
  49.                                     }
  50.                                 }
  51.                             }
  52.                         }
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.         Console.WriteLine(counter);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement