#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100010;
int a[4];
bool cmp1(int b,int c)
{
return b>c;
}
void toarray(int num,int a[])
{
int t=0;
while (t<4)
{
a[t++]=num%10;
num/=10;
}
}
int toint(int a[])
{
int num=0;
for (int i=0;i<4;i++)
num=num*10+a[i];
return num;
}
int main()
{
int n;
cin>>n;
while (1)
{
toarray(n,a);
int temp1,temp2;
sort(a,a+4);
temp1=toint(a);
sort(a,a+4,cmp1);
temp2=toint(a);
n=temp2-temp1;
printf("%04d - %04d = %04d\n",temp2,temp1,n);
if(n==0||n==6174)
break;
}
}
1069 The Black Hole of Numbers (20)数学问题
最新推荐文章于 2024-11-19 22:22:23 发布
本文深入探讨了一个基于数字操作的算法实现,通过不断调整四位数的排列,直至达到固定点6174。文章详细介绍了如何将整数转换为数组,排序并重新组合成新的整数,以及如何通过比较和减法来迭代这一过程,直至得到目标数值6174或0,从而结束循环。
106

被折叠的 条评论
为什么被折叠?



