iliya87

04.MorseCodeNumbersSwitchCase

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