Advertisement
dimipan80

Exam July Morning 4. Morse Code Numbers

Jul 27th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Threading;
  4.  
  5. public class MorseCodeNumbers
  6. {
  7.     public static void Main()
  8.     {
  9.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  10.         checked
  11.         {
  12.             int fourDigitNum = int.Parse(Console.ReadLine());
  13.  
  14.             int digitSum = CalculateTheSumOfDigitsFromTheFourDigitNumber(fourDigitNum);
  15.             bool foundMorseCodeNums = false;
  16.             string[] morseCodes = { "-----", ".----", "..---", "...--", "....-", "....." };
  17.             int m0, m1, m2, m3, m4, m5;
  18.             for (m0 = 0; m0 < morseCodes.Length; m0++)
  19.             {
  20.                 for (m1 = 0; m1 < morseCodes.Length; m1++)
  21.                 {
  22.                     for (m2 = 0; m2 < morseCodes.Length; m2++)
  23.                     {
  24.                         for (m3 = 0; m3 < morseCodes.Length; m3++)
  25.                         {
  26.                             for (m4 = 0; m4 < morseCodes.Length; m4++)
  27.                             {
  28.                                 for (m5 = 0; m5 < morseCodes.Length; m5++)
  29.                                 {
  30.                                     int morseProduct = m0 * m1 * m2 * m3 * m4 * m5;
  31.                                     if (morseProduct == digitSum)
  32.                                     {
  33.                                         foundMorseCodeNums = true;
  34.                                         Console.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|", morseCodes[m0], morseCodes[m1], morseCodes[m2], morseCodes[m3], morseCodes[m4], morseCodes[m5]);
  35.                                     }
  36.                                 }
  37.                             }
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.  
  43.             if (!foundMorseCodeNums)            
  44.             {
  45.                 Console.WriteLine("No");
  46.             }
  47.         }
  48.     }
  49.  
  50.     private static int CalculateTheSumOfDigitsFromTheFourDigitNumber(int number)
  51.     {
  52.         checked
  53.         {
  54.             int sum = 0;            
  55.             do
  56.             {
  57.                 sum += (byte)(number % 10);
  58.                 number /= 10;                
  59.             }
  60.             while (number > 0);
  61.            
  62.             return sum;
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement