Advertisement
felix_de_suza

HayvanNumbers

May 11th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2.  
  3. class HayvanNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         int sum = int.Parse(Console.ReadLine());
  8.         int diff = int.Parse(Console.ReadLine());
  9.         string numberExistingChecker = null;
  10.        
  11.         for (int a = 5; a < 10; a++)
  12.         {
  13.             for (int b = 5; b < 10; b++)
  14.             {
  15.                 for (int c = 5; c < 10; c++)
  16.                 {
  17.                     int abc = int.Parse(""+a+b+c);
  18.                     int def = abc + diff;
  19.                     int ghi = abc + 2 * diff;
  20.                     if (abc < def && def < ghi && (sumOfNumber(abc)+sumOfNumber(def)+sumOfNumber(ghi) == sum) &&
  21.                         isAllowednumber(abc) && isAllowednumber(def) && isAllowednumber(ghi))
  22.                     {
  23.                         Console.WriteLine("{0}{1}{2}", abc, def, ghi);
  24.                         numberExistingChecker = abc.ToString() + def + ghi;
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.         if (numberExistingChecker == null)
  30.         {
  31.             Console.WriteLine("No");
  32.         }
  33.     }
  34.  
  35.     static bool isAllowednumber(int n)
  36.     {
  37.         bool isAllowed = false;
  38.  
  39.         int thirdDigit = n % 10;
  40.         n /= 10;
  41.         int secondDigit = n % 10;
  42.         n /= 10;
  43.         int firstDigit = n % 10;
  44.  
  45.         if (thirdDigit != 0 && secondDigit != 0 && thirdDigit != 0)
  46.         {
  47.             isAllowed = true;
  48.         }
  49.         return isAllowed;
  50.     }
  51.  
  52.     static int sumOfNumber(int n)
  53.     {
  54.         int thirdDigit = n % 10;
  55.         n /= 10;
  56.         int secondDigit = n % 10;
  57.         n /= 10;
  58.         int firstDigit = n % 10;
  59.         int sum = firstDigit + secondDigit + thirdDigit;
  60.         return sum;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement