Last active
August 29, 2015 14:08
-
-
Save amoshyc/197e57c71efa229575fb to your computer and use it in GitHub Desktop.
uva10018.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
long long get_reverse(long long a) { | |
long long rev = 0; | |
while (a != 0) { | |
rev = rev*10 + (a % 10); | |
a /= 10; | |
} | |
return rev; | |
} | |
int is_palindrome(long long a) { | |
if (a == get_reverse(a)) | |
return 1; | |
return 0; | |
} | |
int main() { | |
int N; | |
scanf("%d", &N); | |
while (N--) { | |
long long inp; | |
scanf("%lld", &inp); | |
inp = inp + get_reverse(inp); | |
int cnt = 1; | |
while (is_palindrome(inp) == 0) { | |
inp = inp + get_reverse(inp); | |
cnt++; | |
} | |
printf("%d %lld\n", cnt, inp); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment