Advertisement
fbinnzhivko

04.03 Nine Digit magic Nubers

Apr 27th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class NineDigitMagicNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         int sum = int.Parse(Console.ReadLine());
  8.         int diff = int.Parse(Console.ReadLine());
  9.  
  10.         List<int> list = new List<int>();
  11.         for (int i = 1; i <= 7; i++)
  12.         {
  13.             for (int j = 1; j <= 7; j++)
  14.             {
  15.                 for (int k = 1; k <= 7; k++)
  16.                 {
  17.                     list.Add(i * 100 + j * 10 + k);
  18.                 }
  19.             }
  20.         }
  21.  
  22.         int count = 0;
  23.  
  24.         for (int i = 0; i < list.Count; i++)
  25.         {
  26.             for (int j = 0; j < list.Count; j++)
  27.             {
  28.                 for (int k = 0; k < list.Count; k++)
  29.                 {
  30.                     if (list[k] - list[j] == diff && list[j] - list[i] == diff
  31.                         && (list[i] / 100 + (list[i] / 10) % 10 + list[i] % 10 + list[j] / 100
  32.                         + (list[j] / 10) % 10 + list[j] % 10 + list[k] / 100 + (list[k] / 10) % 10 +
  33.                         list[k] % 10 == sum) && (list[i] <= list[j]) && (list[j] <= list[k]))
  34.                     {
  35.                         count++;
  36.                         Console.Write(list[i] + "" + list[j] + "" + list[k]+"\n");
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.         if (count == 0)
  42.         {
  43.             Console.WriteLine("No");
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement