Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss10018 - | Accepted | C++11 | 0.020 | 0.000 | 14364 | 1 mins ago |
Suggest:
- Create function palindrome(s) to check palindrome string
- Use function to_string(n): integer to string
- Use function stoll(s): string to long long
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
string s;
bool palindrome(string s){
string x="";
for(int i=0; s[i]; i++)
x= s[i] + x;
return (x==s);
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
while(n--){
cin >> s;
int cnt= 0;
do{
cnt++;
string x="";
for(int i=0; s[i]; i++)
x= s[i] + x;
s= to_string(stoll(s) + stoll(x));
}while(!palindrome(s));
cout<<cnt<<" "<<s<<"\n";
}
}
No comments:
Post a Comment