Advertisement
tockata

04. Morse Code Numbers

Jul 25th, 2014
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         int n = int.Parse(Console.ReadLine());
  10.         int sum = 0;
  11.         int firstDigit = n / 1000;
  12.         int secondDigit = (n / 100) % 10;
  13.         int thirdDigit = (n / 10) % 10;
  14.         int fourthDigit = n % 10;
  15.         sum = firstDigit + secondDigit + thirdDigit + fourthDigit;
  16.  
  17.         int one = 0;
  18.         int two = 0;
  19.         int three = 0;
  20.         int four = 0;
  21.         int five = 0;
  22.         int six = 0;
  23.         bool sequenceFound = false;
  24.  
  25.         for (int i = 0; i < 6; i++)
  26.         {
  27.             one = i;
  28.             for (int j = 0; j < 6; j++)
  29.             {
  30.                 two = j;
  31.                 for (int k = 0; k < 6; k++)
  32.                 {
  33.                     three = k;
  34.                     for (int m = 0; m < 6; m++)
  35.                     {
  36.                         four = m;
  37.                         for (int o = 0; o < 6; o++)
  38.                         {
  39.                             five = o;
  40.                             for (int p = 0; p < 6; p++)
  41.                             {
  42.                                 six = p;
  43.                                 int product = one * two * three * four * five * six;
  44.                                 if (product == sum)
  45.                                 {
  46.                                     sequenceFound = true;
  47.                                     string result = "" + one + two + three + four + five + six;
  48.                                     foreach (char digit in result)
  49.                                     {
  50.                                         switch (digit)
  51.                                         {
  52.                                             case '0': Console.Write("-----|"); break;
  53.                                             case '1': Console.Write(".----|"); break;
  54.                                             case '2': Console.Write("..---|"); break;
  55.                                             case '3': Console.Write("...--|"); break;
  56.                                             case '4': Console.Write("....-|"); break;
  57.                                             case '5': Console.Write(".....|"); break;
  58.                                             default: break;
  59.                                         }
  60.                                        
  61.                                     }
  62.                                     Console.WriteLine();
  63.                                 }
  64.                             }
  65.                         }
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.         if (sequenceFound == false)
  71.         {
  72.             Console.WriteLine("No");
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement