Advertisement
ralka

Master Numbers

May 24th, 2016
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 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 _25.Master_Numbers
  8. {
  9.     class MasterNumbers
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             long num = long.Parse(Console.ReadLine());
  14.  
  15.             for (int i = 1; i <= num; i++)
  16.             {
  17.                 if (IsPalndrome(i))
  18.                 {
  19.                     if (SumOfDigits(i))
  20.                     {
  21.                         if (ContainsEvenDigit(i))
  22.                         {
  23.                             Console.WriteLine(i);
  24.                         }
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.  
  30.         private static bool ContainsEvenDigit(int i)
  31.         {
  32.             while (i != 0)
  33.             {
  34.                 if ((i % 10) % 2 == 0)
  35.                 {
  36.                     return true;
  37.                 }
  38.                 i = i / 10;
  39.             }
  40.             return false;
  41.         }
  42.  
  43.         private static bool SumOfDigits(int i)
  44.         {
  45.             long sum = FindSum(i);
  46.             if (sum % 7 == 0)
  47.             {
  48.                 return true;
  49.             }
  50.             return false;
  51.         }
  52.  
  53.         private static long FindSum(int i)
  54.         {
  55.             long sum = 0;
  56.             while (i != 0)
  57.             {
  58.                 sum += i % 10;
  59.                 i = i / 10;
  60.             }
  61.             return sum;
  62.         }
  63.  
  64.         private static bool IsPalndrome(int arg)
  65.         {
  66.             bool palindrome = true;
  67.             string num = arg.ToString();
  68.             for (int i = 0; i <= num.Length / 2; i++)
  69.             {
  70.                 if (num[i] != num[num.Length - 1 - i])
  71.                 {
  72.                     palindrome = false;
  73.                     break;
  74.                 }
  75.             }
  76.             return palindrome;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement