fbinnzhivko

04.01 Hayvan Numbers

May 2nd, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. class HayvanNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         int sum = int.Parse(Console.ReadLine());
  8.         int diff = int.Parse(Console.ReadLine());
  9.  
  10.         int a;   int b;    int c;
  11.         string num;
  12.         int counter = 0;
  13.  
  14.         for (int i = 555; i <= 999; i++)
  15.         {
  16.             int tempSum = 0;
  17.             a = i;
  18.             b = a + diff;
  19.             c = b + diff;
  20.  
  21.             num = a.ToString() + b + c;
  22.             Regex r = new Regex("0|1|2|3|4");
  23.             if (!r.IsMatch(num))
  24.             {
  25.                 for (int j = 0; j < num.Length; j++)
  26.                 {
  27.                     tempSum += Convert.ToInt32(num[j].ToString());
  28.                 }
  29.  
  30.                 if (tempSum == sum && num.Length == 9)
  31.                 {
  32.                     Console.WriteLine(num);
  33.                     counter++;
  34.                 }
  35.             }
  36.         }
  37.  
  38.         if (counter == 0)
  39.         {
  40.             Console.WriteLine("No");
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment