此代码在dev上完美运行但在gcc上导致运行时错误?我能知道为什么吗? 该程序用于查找最小迭代次数以连续添加数字及其反向,直到达到回文数。
#include<iostream>
using namespace std;
unsigned long palin(unsigned long A)
{
unsigned long S=0, B;
int d=0;
B=A;
while ( B!=0 )
{
d=B%10;
S=S*10+d;
B/=10;
}
return S;
}
int main()
{
int n,j,c;
unsigned long P,Q;
cin>>n;
for( int i=1; i<=n; i++ )
{
cin>>P;
c=0;
Q=palin(P);
if( Q!=P )
while( Q != P && c<1000 )
{
P=Q+P;
Q=palin(P);
c++;
}
cout << c << " " << Q << endl;
}
return 1;
}