Saturday, July 19, 2014

UVa - 10018 - Reverse and Add

#include <iostream>
using namespace std;

int main(){
    int t;
    long long n, rev, real, mod, temp;
    cin >> t;
    while(t--){
        cin >> n;
        int cnt = 0;
        while(1){
            real = n;
            rev = 0;
            while(n > 0){
                mod = n % 10;
                rev = (rev*10) + mod;
                n /= 10;
            }
            if(rev == real)break;
            real += rev; n = real; cnt++;
        }
        cout << cnt << " " << rev << endl;
    }
    return 0;
}

No comments:

Post a Comment