Skip to content

Instantly share code, notes, and snippets.

@amoshyc
Last active August 29, 2015 14:08
Show Gist options
  • Save amoshyc/197e57c71efa229575fb to your computer and use it in GitHub Desktop.
Save amoshyc/197e57c71efa229575fb to your computer and use it in GitHub Desktop.
uva10018.c
#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