svetlozar_kirkov

Winning Numbers

Sep 15th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace WinningNumbers
  7. {
  8.     class WinningNumbers
  9.     {
  10.         static void Main()
  11.         {
  12.             string input = Console.ReadLine();
  13.             char[] inputArray = input.ToLower().ToCharArray();
  14.             int sum = 0;
  15.            
  16.             foreach (var item in inputArray)
  17.             {
  18.                 sum+=Convert.ToInt32(item)-96;
  19.             }
  20.  
  21.             List<string> collected = new List<string>();
  22.  
  23.             if (sum > 729)
  24.             {
  25.                 Console.WriteLine("No");
  26.                 return;
  27.             }
  28.             else
  29.             {
  30.                 for (int i = 111; i < 999; i++)
  31.                 {
  32.                     int[] tempNum = Array.ConvertAll(i.ToString().ToArray(), x => (int)x - 48);
  33.                     if (tempNum[0] * tempNum[1] * tempNum[2] == sum)
  34.                     {
  35.                         string num = String.Join("", tempNum.Select(p => p.ToString()).ToArray());
  36.                         collected.Add(num);
  37.                     }
  38.                 }
  39.             }
  40.  
  41.  
  42.             if (collected.Count == 0)
  43.             {
  44.                 Console.WriteLine("No");
  45.                 return;
  46.             }
  47.             else
  48.             {
  49.                 for (int k = 0, i = 0, j = 0; k < collected.Count * collected.Count; k++)
  50.                 {
  51.                     if (j == collected.Count)
  52.                     {
  53.                         i++;
  54.                         j = 0;
  55.                         Console.WriteLine(collected[i] + "-" + collected[j]);
  56.                         j++;
  57.  
  58.                     }
  59.                     else
  60.                     {
  61.                         Console.WriteLine(collected[i] + "-" + collected[j]);
  62.                         j++;
  63.  
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.  
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment