UVa online judge
problem:10018
(reverse and add)
problem:https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=959
solution:
#include<bits/stdc++.h>
using namespace std;
long long int power(int x,long long int y)
{
long long int ans=1;
for(long long int z=1; z<=y; z++) ans*=x;
return ans;
}
int main()
{
long long int T;
scanf("%lld",&T);
while(T--)
{
vector<int>digit;
long long int i,k=0,j,d,a,n,c=0,p,carry;
scanf("%lld",&a);
n=a;
while(n>0)
{
digit.push_back(n%10);
n/=10;
}
for(i=0,j=digit.size()-1; i<=j; i++,j--)
if(digit[i]!=digit[j])
{
c=1;
break;
}
if(c==1)
while(c==1)
{
c=0,n=a,p=0,d=0,i=digit.size()-1;
while(n>0)
{
d+=(((n%10)+digit[i])*power(10,p));
p++;
i--;
n/=10;
}
digit.clear();
a=d,n=a;
while(n>0)
{
digit.push_back(n%10);
n/=10;
}
for(i=0,j=digit.size()-1; i<=j; i++,j--)
if(digit[i]!=digit[j])
{
c=1;
break;
}
k++;
}
printf("%lld %lld\n",k,a);
}
return 0;
}
using namespace std;
long long int power(int x,long long int y)
{
long long int ans=1;
for(long long int z=1; z<=y; z++) ans*=x;
return ans;
}
int main()
{
long long int T;
scanf("%lld",&T);
while(T--)
{
vector<int>digit;
long long int i,k=0,j,d,a,n,c=0,p,carry;
scanf("%lld",&a);
n=a;
while(n>0)
{
digit.push_back(n%10);
n/=10;
}
for(i=0,j=digit.size()-1; i<=j; i++,j--)
if(digit[i]!=digit[j])
{
c=1;
break;
}
if(c==1)
while(c==1)
{
c=0,n=a,p=0,d=0,i=digit.size()-1;
while(n>0)
{
d+=(((n%10)+digit[i])*power(10,p));
p++;
i--;
n/=10;
}
digit.clear();
a=d,n=a;
while(n>0)
{
digit.push_back(n%10);
n/=10;
}
for(i=0,j=digit.size()-1; i<=j; i++,j--)
if(digit[i]!=digit[j])
{
c=1;
break;
}
k++;
}
printf("%lld %lld\n",k,a);
}
return 0;
}
//Language:C++
No comments:
Post a Comment