Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Palindrom
- {
- class Program
- {
- static int count;
- static void Main(string[] args)
- {
- string pal = palindrom(args[0]);
- int cnt = count;
- Console.WriteLine("{0} steps and palindrome={1}",cnt,pal);
- Console.ReadKey();
- }
- static string palindrom(string test)
- {
- if (test == ReverseString(test))
- {
- return test;
- }
- else
- {
- int temp = Convert.ToInt32(test) + Convert.ToInt32(ReverseString(test));
- count += 1;
- return palindrom(Convert.ToString(temp));
- }
- }
- static string ReverseString(string s)
- {
- char[] arr = s.ToCharArray();
- Array.Reverse(arr);
- return new string(arr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement