题目:给定把一个数字a,每次变为a和a的反转的加和,的那个a自反是停止。
分析:简单题。直接计算即可。
注意:数据范围超过int。
#include <iostream>
#include <cstdlib>
using namespace std;
typedef long long LL;
LL rev( LL n )
{
LL v = 0LL;
while ( n ) {
v *= 10LL;
v += n%10LL;
n /= 10LL;
}
return v;
}
int main()
{
int T;
while ( cin >> T )
for ( int t = 1 ; t <= T ; ++ t ) {
LL a,b;
cin >> a;
b = rev(a);
int count = 0;
while ( a != b ) {
a = a+b;
b = rev(a);
count ++;
}
cout << count << " " << a << endl;
}
return 0;
}