Advertisement
Miklak

Amusing Sums

Oct 21st, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. /* http://gosucoder.com/problem/P1 */
  2.  
  3. using System;
  4.  
  5. public class Test
  6. {
  7.     static int c;
  8.     static void Main(string[] args)
  9.     {
  10.         int n = int.Parse(Console.ReadLine());
  11.         int[] a = new int[n];
  12.         for (int i = 0; i < n; i++)
  13.             a[i] = int.Parse(Console.ReadLine());
  14.  
  15.         for (int i = 0; i < n; i++)
  16.         {
  17.             c = 0;
  18.             Console.WriteLine(AmusingSum(a[i]) + " " + c);
  19.         }
  20.         Console.ReadLine();
  21.     }
  22.  
  23.     static int AmusingSum(int x)
  24.     {
  25.         int y = Reverse(x);
  26.         if (x == y)
  27.             return x;
  28.         else
  29.         {
  30.             c++;
  31.             return AmusingSum(x + y);
  32.         }
  33.     }
  34.  
  35.     static int Reverse(int x)
  36.     {
  37.         int r = 0;
  38.         do {
  39.             r = 10 * r + x % 10;
  40.             x /= 10;
  41.         } while (x > 0);
  42.         return r;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement