iliya87

04.MorseCodeNumbers

Mar 27th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class MorseCodeNumbers
  5. {
  6.     static void Main()
  7.     {
  8.         Dictionary<int, string> morseEncoding = new Dictionary<int, string>
  9.         {
  10.             {1, ".----"},
  11.             {2, "..---"},
  12.             {3, "...--"},
  13.             {4, "....-"},
  14.             {5, "....."}
  15.         };
  16.  
  17.         int n = int.Parse(Console.ReadLine()); //1234
  18.         int nSum = 0;
  19.         bool hasAnwer = false;
  20.  
  21.         while (n != 0)
  22.         {
  23.             //Getting the current digit of the number
  24.             int remainder = n % 10;
  25.             //Summing up the digit to the total sum
  26.             nSum += remainder;
  27.             //Removing the last digit from the number
  28.             n /= 10;
  29.         }
  30.  
  31.         for (int i = 1; i <= 5; i++)
  32.         {
  33.             for (int j = 1; j <= 5; j++)
  34.             {
  35.                 for (int k = 1; k <= 5; k++)
  36.                 {
  37.                     for (int l = 1; l <= 5; l++)
  38.                     {
  39.                         for (int m = 1; m <= 5; m++)
  40.                         {
  41.                             for (int o = 1; o <= 5; o++)
  42.                             {
  43.                                 int product = i * j * k * l * m * o;
  44.                                 if (product == nSum)
  45.                                 {
  46.                                     Console.WriteLine(morseEncoding[i] + '|' +
  47.                                                         morseEncoding[j] + '|' +
  48.                                                         morseEncoding[k] + '|' +
  49.                                                         morseEncoding[l] + '|' +
  50.                                                         morseEncoding[m] + '|' +
  51.                                                         morseEncoding[o] + '|');
  52.                                     hasAnwer = true;
  53.                                 }
  54.                             }
  55.                         }
  56.                     }
  57.                 }
  58.             }
  59.         }
  60.  
  61.         if (hasAnwer != true)
  62.             Console.WriteLine("No");
  63.  
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment