Guest User

Untitled

a guest
Apr 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 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 ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. private static int MAX = 1000000;
  12. static void Main(string[] args)
  13. {
  14. int sum = 0;
  15. for(int x = 1; x < MAX; x++)
  16. {
  17. if(x % 10 != 0)
  18. {
  19. if (isPalindrome(x.ToString()))
  20. {
  21. if(isPalindrome(Convert.ToString(x, 2)))
  22. {
  23. sum += x;
  24. }
  25. }
  26. }
  27. }
  28. Console.WriteLine(sum);
  29. Console.ReadKey();
  30. }
  31.  
  32. static bool isPalindrome(string x)
  33. {
  34. char[] number = x.ToCharArray();
  35. char[] reverseNumber = x.ToCharArray();
  36. if (reverseNumber[0] == '0') return false;
  37. Array.Reverse(reverseNumber);
  38. for(int i = 0; i < number.Count(); i++)
  39. {
  40. if((number[i] != reverseNumber[i]))
  41. {
  42. return false;
  43. }
  44. }
  45. return true;
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment