Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class NineDigitMagicNumber
- {
- static void Main()
- {
- short sum = short.Parse(Console.ReadLine());
- short diff = short.Parse(Console.ReadLine());
- int sumOfNumber = 0;
- bool isEual = false;
- for (short i1 = 1; i1 <=7; i1++)
- {
- for (short i2 = 1; i2 <=7; i2++)
- {
- for (short i3 = 1; i3 <=7; i3++)
- {
- for (short i4 = 1; i4 <=7; i4++)
- {
- for (short i5 = 1; i5 <=7; i5++)
- {
- for (short i6 = 1; i6 <=7; i6++)
- {
- for (short i7 = 1; i7 <=7; i7++)
- {
- for (short i8 = 1; i8 <=7; i8++)
- {
- for (short i9 = 1; i9 <=7; i9++)
- {
- sumOfNumber = i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9;
- if (sumOfNumber == sum)
- {
- string firstP = i1 + " " + i2 + " " + i3;
- firstP = firstP.Replace(" ", "");
- string secondP = i4 + " " + i5 + " " + i6;
- secondP = secondP.Replace(" ", "");
- string thirdP = i7 + " " + i8 + " " + i9;
- thirdP = thirdP.Replace(" ", "");
- short firstPair = short.Parse(firstP);
- short secondPair = short.Parse(secondP);
- short thirdPair = short.Parse(thirdP);
- if (secondPair - firstPair == diff && thirdPair - secondPair == diff)
- {
- isEual = true;
- Console.Write(firstP);
- Console.Write(secondP);
- Console.Write(thirdPair);
- Console.WriteLine();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (isEual==false)
- {
- Console.WriteLine("No");
- }
- }
- }
Add Comment
Please, Sign In to add comment