Advertisement
akass

Palindrom

Apr 23rd, 2015
255
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.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Palindrom
  8. {
  9.     class Program
  10.     {
  11.         static int count;
  12.         static void Main(string[] args)
  13.         {
  14.             string pal = palindrom(args[0]);
  15.             int cnt = count;
  16.             Console.WriteLine("{0} steps and palindrome={1}",cnt,pal);
  17.             Console.ReadKey();
  18.         }
  19.  
  20.         static string palindrom(string test)
  21.         {
  22.             if (test == ReverseString(test))
  23.             {
  24.                 return test;
  25.             }
  26.             else
  27.             {
  28.                 int temp = Convert.ToInt32(test) + Convert.ToInt32(ReverseString(test));
  29.                 count += 1;
  30.                 return palindrom(Convert.ToString(temp));
  31.             }
  32.         }
  33.         static string ReverseString(string s)
  34.         {
  35.             char[] arr = s.ToCharArray();
  36.             Array.Reverse(arr);
  37.             return new string(arr);
  38.         }
  39.  
  40.     }
  41.        
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement