Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int sum = int.Parse(Console.ReadLine());
  9.         int diff = int.Parse(Console.ReadLine());
  10.         bool hasHyvanNumers = false;
  11.  
  12.         for (int i = 555; i <= 999; i++)
  13.         {
  14.             int abc = i;
  15.             int def = abc + diff;
  16.             int ghi = def + diff;
  17.             if (ghi > 999) break;
  18.             string allNums = "" + abc + def + ghi;
  19.             if (allNums.Contains("0") || allNums.Contains("1") || allNums.Contains("2") || allNums.Contains("3") || allNums.Contains("4")) continue;
  20.             int totalSum = allNums.Sum(t => Convert.ToInt32(Convert.ToString(t)));
  21.             if (totalSum == sum)
  22.             {
  23.                 Console.WriteLine(allNums);
  24.                 hasHyvanNumers = true;
  25.             }
  26.         }
  27.  
  28.         if (!hasHyvanNumers) Console.WriteLine("No");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement