~cpp
// no10018 - Reverse and Add
#include <iostream>
#include <cmath>
using namespace std;
int makePalim(unsigned int * pal, unsigned int originN, int count);
void showPalim(const unsigned int * pal, const int * nadd, const int n);
int main()
{
int n; // test의 수
int i;
unsigned int num; // test
cin >> n;
unsigned int * palim = new unsigned int[n]; // palindrome
int * nAdd = new int[n]; // add의 수
for (i=0; i<n; i++)
{
cin >> num;
nAdd[i] = makePalim(palim, num, i);
}
showPalim(palim, nAdd, i);
delete [] nAdd;
delete [] palim;
return 0;
}
int makePalim(unsigned int * pal, unsigned int originN, int count)
{
int nadd = 0; // add의 수
unsigned int reverseN; // reverse한 수
int len, i; // 자리수
unsigned int temp, t;
while(true)
{
reverseN = 0;
len = 1;
temp = originN;
while (temp / 10 != 0)
{
len++;
temp /= 10;
}
temp = originN;
for (i=0; i<len; i++)
{
t = temp / pow(10, len-1-i);
reverseN += t * pow(10, i);
temp -= t * pow(10, len-1-i);
}
if (originN == reverseN)
break;
originN = originN + reverseN;
nadd++;
}
pal[count] = originN;
return nadd;
}
void showPalim(const unsigned int * pal, const int * nadd, const int n)
{
int i;
for (i=0; i<n; i++)
cout << nadd[i] << " " << pal[i] << endl;
}