Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Threading;
- public class MorseCodeNumbers
- {
- public static void Main()
- {
- Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
- checked
- {
- int fourDigitNum = int.Parse(Console.ReadLine());
- int digitSum = CalculateTheSumOfDigitsFromTheFourDigitNumber(fourDigitNum);
- bool foundMorseCodeNums = false;
- string[] morseCodes = { "-----", ".----", "..---", "...--", "....-", "....." };
- int m0, m1, m2, m3, m4, m5;
- for (m0 = 0; m0 < morseCodes.Length; m0++)
- {
- for (m1 = 0; m1 < morseCodes.Length; m1++)
- {
- for (m2 = 0; m2 < morseCodes.Length; m2++)
- {
- for (m3 = 0; m3 < morseCodes.Length; m3++)
- {
- for (m4 = 0; m4 < morseCodes.Length; m4++)
- {
- for (m5 = 0; m5 < morseCodes.Length; m5++)
- {
- int morseProduct = m0 * m1 * m2 * m3 * m4 * m5;
- if (morseProduct == digitSum)
- {
- foundMorseCodeNums = true;
- Console.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|", morseCodes[m0], morseCodes[m1], morseCodes[m2], morseCodes[m3], morseCodes[m4], morseCodes[m5]);
- }
- }
- }
- }
- }
- }
- }
- if (!foundMorseCodeNums)
- {
- Console.WriteLine("No");
- }
- }
- }
- private static int CalculateTheSumOfDigitsFromTheFourDigitNumber(int number)
- {
- checked
- {
- int sum = 0;
- do
- {
- sum += (byte)(number % 10);
- number /= 10;
- }
- while (number > 0);
- return sum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement