#include<bits/stdc++.h>
#define i64 long long
#define mx(a,b,c) max(a,max(b,c))
#define mn(a,b,c) min(a,min(b,c))
#define eef else if
#define ff(i,s,e) for(int i=(s); i<e; i++)
#define ff2(i,s,e) for(int i=(s); i>=e; i--)
#define sf scanf
#define pf printf
#define dbug(x) cout<<"x = "<<x<<endl
#define newl cout<<"\n"
#define putcase cout<<"Case "<<++cse<<":"
#define putcase2 cout<<"Case #"<<++cse<<":"
using namespace std;
bool isPalindrome(long long x){
stringstream strm;
strm<<x;
string org=strm.str();
string temp=org;
reverse(org.begin(),org.end());
if(temp!=org){
// cout<<org;
return false;
}
return true;
}
int main()
{
long long sum=0;
long long num;
int t,cnt=0;
cin>>t;
while(t--){
cin>>num;
if(isPalindrome(num)==true){
cnt=0;
// dbug(cnt);
}
else{
while(1){
stringstream ss;
ss<<num;
string rev=ss.str();
reverse(rev.begin(),rev.end());
long long revNum=atoi(rev.c_str());
sum=num+revNum;
if(isPalindrome(sum)==true){
cnt++;
break;
}
else
cnt++;
num=sum;
}
}
cout<<cnt<<" "<<sum<<endl;
cnt=0;
}
return 0;
}
#define i64 long long
#define mx(a,b,c) max(a,max(b,c))
#define mn(a,b,c) min(a,min(b,c))
#define eef else if
#define ff(i,s,e) for(int i=(s); i<e; i++)
#define ff2(i,s,e) for(int i=(s); i>=e; i--)
#define sf scanf
#define pf printf
#define dbug(x) cout<<"x = "<<x<<endl
#define newl cout<<"\n"
#define putcase cout<<"Case "<<++cse<<":"
#define putcase2 cout<<"Case #"<<++cse<<":"
using namespace std;
bool isPalindrome(long long x){
stringstream strm;
strm<<x;
string org=strm.str();
string temp=org;
reverse(org.begin(),org.end());
if(temp!=org){
// cout<<org;
return false;
}
return true;
}
int main()
{
long long sum=0;
long long num;
int t,cnt=0;
cin>>t;
while(t--){
cin>>num;
if(isPalindrome(num)==true){
cnt=0;
// dbug(cnt);
}
else{
while(1){
stringstream ss;
ss<<num;
string rev=ss.str();
reverse(rev.begin(),rev.end());
long long revNum=atoi(rev.c_str());
sum=num+revNum;
if(isPalindrome(sum)==true){
cnt++;
break;
}
else
cnt++;
num=sum;
}
}
cout<<cnt<<" "<<sum<<endl;
cnt=0;
}
return 0;
}
No comments:
Post a Comment