using namespace std;
int reverse(int num)
{
int d = 0;
while (num)
{
d = d * 10 + num % 10;
num /= 10;
}
return d;
}
bool isHW(int num)
{
return num == reverse(num);
}
int main()
{
int num;
scanf(“%d”, &num);
for (int i = 1; i <= 1000; ++i)
{
num = num + reverse(num);
if (isHW(num))
{
printf(“%d %d\n”,i,num);
break;
}
}
return 0;
}
瞎几把签到
一种写法,供参考
抱歉,出了点错误,更正如下
include
using namespace std;
int n,tot=0;
char strs[1000],strs2[1000];
int ishui(int aa)
{
sprintf(strs,”%d”,aa);
int ll=strlen(strs);
for(int i=0;i<ll/2;i++) if(strs[i]!=strs[ll-i-1]) return 0;
return 1;
}
int reverse(int aa)
{
sprintf(strs,”%d”,aa);
int ll=strlen(strs);
for(int i=ll-1;i>=0;i–) strs2[i]=strs[ll-i-1];
strs2[ll]=’\0’;
int ret;
sscanf(strs2,”%d”,&ret);
return ret;
}
int get_next(int aa)
{
return aa+reverse(aa);
}
int main()
{
cin>>n;
while(!ishui(n))
{
n=get_next(n);
tot++;
}
cout<<tot<<” “<<n<<endl;
return 0;
}
一种写法,供参考
include
using namespace std;
int n,tot=0;
char strs[1000],strs2[1000];
int ishui(int aa)
{
sprintf(strs,”%d”,aa);
int ll=strlen(strs);
for(int i=0;i<ll/2;i++) if(strs[i]!=strs[ll-i-1]) return 0;
else return 1;
}
int reverse(int aa)
{
sprintf(strs,”%d”,aa);
int ll=strlen(strs);
for(int i=ll-1;i>=0;i–) strs2[i]=strs[ll-i-1];
strs2[ll]=’\0’;
int ret;
sscanf(strs2,”%d”,&ret);
return ret;
}
int get_next(int aa)
{
return aa+reverse(aa);
}
int main()
{
cin>>n;
while(!ishui(n))
{
n=get_next(n);
tot++;
}
cout<<tot<<” “<<n<<endl;
return 0;
}
简单易懂的死算
include
include
include
include
int main()
{
int n;
scanf(“%d”,&n);
int b[20],k=0;
k=n;
for(int i=0;i<20;i++)
{
b[i]=0;
}
int t=0;
while(k!=0)
{
b[t]=k%10;
k=k/10;
t++;
}
int sum=0;
for(int i=0;i<t;i++)
{
sum=sum10+b[i];
}
int j=0;
while(sum!=n)
{
j++;
int num=0;
num=sum+n;
n=num;
k=num;
for(int i=0;i<20;i++)
{
b[i]=0;
}
int t=0;
while(k!=0)
{
b[t]=k%10;
k=k/10;
t++;
}
sum=0;
for(int i=0;i<t;i++)
{
sum=sum10+b[i];
}
}
printf(“%d %d\n”,j,sum);
return 0;
}
def fun(n, m):
return(n + m)
def reverse(n):
return(int(str(n)[::-1]))
n = int(input())
i = 0
m = reverse(n)
while m != n:
n = fun(m, n)
m = reverse(n)
i += 1
print(‘%d %d’ % (i ,n))
include
include
using namespace std;
int reverse(int num)
{
int d = 0;
while (num)
{
d = d * 10 + num % 10;
num /= 10;
}
return d;
}
bool isHW(int num)
{
return num == reverse(num);
}
int main()
{
int num;
scanf(“%d”, &num);
for (int i = 1; i <= 1000; ++i)
{
num = num + reverse(num);
if (isHW(num))
{
printf(“%d %d\n”,i,num);
break;
}
}
return 0;
}