Advertisement
braveheart1989

Special numbers

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