可恨的pow(……)函数

因为***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 条评论

  • 1

信息

ID
1304
难度
5
分类
模拟 点击显示
标签
递交数
8066
已通过
2523
通过率
31%
被复制
28
上传者