10018 - Reverse and Add

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    long long int a,b,c,d,N,t,i,count,sum;
    char str[100],str1[100];
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&N);
        count=0;
        while(1)
        {
            c=N;
            b=0;
            while(N!=0)
            {
                b=b*10+(N%10);
                N=N/10;
            }
            N=b;
            N+=c;
            sprintf(str,"%lld",N);
            a=strlen(str);
            strcpy(str1,str);
            reverse(str1,str1+a);
            if(strcmp(str1,str)==0)
            {
                d=0;
                for(i=0; i<a; i++)
                {
                    sum=d*10+str1[i]-48;
                    d=sum;
                }
                break;
            }
            count++;
            reverse(str1,str1+a);
            d=0;
            for(i=0; i<a; i++)
            {
                N=d*10+str1[i]-48;
                d=N;
            }
        }
        printf("%lld %lld\n",count+1,sum);
    }
    return 0;
}

0 comments: (+add yours?)