- 回文数
- 2016-06-05 18:37:44 @
因为***pow***,害我找了那么长时间的错!!!
c++
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
//#define try
//#define try1
#define Int long long
#define pause system("pause")
Int n;
string _n(Int m){
string s="";
while(m){
Int a=m%n;
char c;
if(a<10)c=a+'0';else
c=a-10+'A';
s=c+s;
m/=n;
}
#ifdef try
cout<<s<<endl;
pause;
#endif
return s;
}
Int _10(string a){
Int m=0,p;
for(Int i=0;i<a.length();i++){
p=a.length()-i-1;
char c=a[p];
if(c>='A'&&c<='F')c=10+c-'A';
else c-='0';
double s=pow(n,p)+0.5;//因为这个0.5,害我找了半天的错,万恶的pow
m+=(Int)s*c;
}
#ifdef try
cout<<m<<endl;
pause;
#endif
return m;
}
int main(void){
Int step=0;
string m;
cin>>n>>m;
while(step<=30){
string s,s1;
s=s1=m;
#ifdef try
cout<<s<<endl;
pause;
#endif
reverse(s1.begin(),s1.end());
#ifdef try
cout<<s1<<endl;
pause;
#endif
if(s==s1)break;
Int a=_10(s),b=_10(s1);
Int ss=a+b;
m=_n(ss);
step++;
#ifdef try1
cout<<"STEP"<<step<<':'<<
s+"+"+s1+"="<<m<<endl;
pause;
#endif
}
if(step>30)
cout<<"Impossible!"<<endl;else
cout<<"STEP="<<step<<endl;
return 0;
}
感谢q234rty大神
5 条评论
-
Jimmy_Lian LV 4 @ 2020-05-09 17:38:44
考古
-
2020-05-09 17:29:52@
前排%%%
-
2020-05-09 17:12:17@
考古(
-
2017-10-06 09:15:40@
还以为你错了**半年**,吓死我了
-
2016-06-05 18:39:00@
窝是渣渣QAQ
%%%mrsrz小学大神
- 1