Advertisement
dimipan80

Exam 8. Magic Car Numbers

Jun 22nd, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Threading;
  4.  
  5. public class MagicCarNumbers
  6. {
  7.     public static void Main()
  8.     {
  9.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  10.         checked
  11.         {
  12.             int magicWeight = int.Parse(Console.ReadLine());
  13.  
  14.             int magicCarNums = 0;
  15.             if (magicWeight >= 60)
  16.             {
  17.                 char[] carLetters = { 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'P', 'T', 'X' };
  18.                 int[] weightLetters = { 10, 20, 30, 50, 80, 110, 130, 160, 200, 240 };                
  19.                 magicWeight -= 40;
  20.                 for (int a = 0; a < 10; a++)
  21.                 {
  22.                     for (int b = 0; b < 10; b++)
  23.                     {
  24.                         for (int c = 0; c < 10; c++)
  25.                         {
  26.                             for (int d = 0; d < 10; d++)
  27.                             {
  28.                                 bool digitsIsMagic = (b == a && c == a && d == a) || (c == b && d == b)
  29.                                     || (b == a && c == a) || (b == a && d == c) || (c == a && d == b)
  30.                                     || (d == a && c == b);
  31.  
  32.                                 if (digitsIsMagic)
  33.                                 {
  34.                                     int sumDigits = a + b + c + d;
  35.                                     for (int x = 0; x < carLetters.Length; x++)
  36.                                     {
  37.                                         for (int y = 0; y < carLetters.Length; y++)
  38.                                         {
  39.                                             int sumLetters = weightLetters[x] + weightLetters[y];
  40.                                             if (sumDigits + sumLetters == magicWeight)
  41.                                             {
  42.                                                 magicCarNums++;                                              
  43.                                             }                                            
  44.                                         }
  45.                                     }
  46.                                 }
  47.                             }
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.  
  53.             Console.WriteLine(magicCarNums);
  54.         }
  55.     }    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement