Advertisement
Guest User

C# Basics Exam 10 April 2014 Morning - 04. Nine Digit Magic

a guest
Aug 21st, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int sum = Convert.ToInt32(Console.ReadLine());
  14.             int diff = Convert.ToInt32(Console.ReadLine());
  15.             bool isMagic = false;
  16.             for (int a = 1; a < 8; a++)
  17.             {
  18.                 for (int b = 1; b < 8; b++)
  19.                 {
  20.                     for (int c = 1; c < 8; c++)
  21.                     {
  22.                         for (int d = 1; d < 8; d++)
  23.                         {
  24.                             for (int e = 1; e < 8; e++)
  25.                             {
  26.                                 for (int f = 1; f < 8; f++)
  27.                                 {
  28.                                     for (int g = 1; g < 8; g++)
  29.                                     {
  30.                                         for (int h = 1; h < 8; h++)
  31.                                         {
  32.                                             for (int i = 1; i < 8; i++)
  33.                                             {
  34.                                                 int num1 = 100 * (a) + 10 * (b) + c;
  35.                                                 int num2 = 100 * (d) + 10 * (e) + f;
  36.                                                 int num3 = 100 * (g) + 10 * (h) + i;
  37.                                                 int sum1 = a + b + c + d + e + f + g + h + i;
  38.                                                 if (sum1 == sum && num3 - num2 == diff && num2 - num1 == diff && num1<num2 && num2<num3)
  39.                                                 {
  40.                                                     isMagic = true;
  41.                                                     Console.Write(num1);
  42.                                                     Console.Write(num2);
  43.                                                     Console.WriteLine(num3);
  44.  
  45.                                                 }
  46.                                             }
  47.  
  48.                                         }
  49.                                     }
  50.                                 }
  51.                             }
  52.                         }
  53.                     }
  54.                 }
  55.             }
  56.             if (isMagic != true)
  57.             {
  58.                 Console.WriteLine("No");
  59.             }
  60.             Console.ReadLine();
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement