Advertisement
zdravko7

[C# Beginner Exam] Nine Digit Magic Numbers

Aug 6th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 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 Nine_Digit_Magic_Numbers
  8. {
  9.     class MagicNumbers
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int sumOfNum = int.Parse(Console.ReadLine());
  14.             int difference = int.Parse(Console.ReadLine());
  15.             int counter = 0;
  16.  
  17.             for (int i1 = 1; i1 <= 7; i1++)
  18.             {
  19.                 for (int i2 = 1; i2 <= 7; i2++)
  20.                 {
  21.                     for (int i3 = 1; i3 <= 7; i3++)
  22.                     {
  23.                         for (int i4 = 1; i4 <= 7; i4++)
  24.                         {
  25.                             for (int i5 = 1; i5 <= 7; i5++)
  26.                             {
  27.                                 for (int i6 = 1; i6 <= 7; i6++)
  28.                                 {
  29.                                     int firstThree = int.Parse("" + i1 + i2 + i3);
  30.                                     int secondThree = int.Parse("" + i4 + i5 + i6);
  31.  
  32.                                     if (secondThree - firstThree == difference && secondThree > firstThree)
  33.                                     {
  34.                                         for (int i7 = 1; i7 <= 7; i7++)
  35.                                         {
  36.                                             for (int i8 = 1; i8 <= 7; i8++)
  37.                                             {
  38.                                                 for (int i9 = 1; i9 <= 7; i9++)
  39.                                                 {
  40.                                                     if ((i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9) == sumOfNum)
  41.                                                     {
  42.                                                         int lastThree = int.Parse("" + i7 + i8 + i9);
  43.  
  44.                                                         if (secondThree - firstThree == difference
  45.                                                               && lastThree - secondThree == difference
  46.                                                                   && lastThree > secondThree && secondThree > firstThree)
  47.                                                         {
  48.                                                             Console.WriteLine("" + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9);
  49.                                                             counter++;
  50.                                                         }
  51.                                                     }
  52.                                                 }
  53.                                             }
  54.                                         }
  55.                                     }
  56.                                 }
  57.                             }
  58.                         }
  59.                     }
  60.                 }
  61.             }
  62.  
  63.             if (counter == 0)
  64.             {
  65.                 Console.WriteLine("No");
  66.             }
  67.            
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement