//代码每次提交分数都不一样。。。原因不明,偶尔满分
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int Maxn = 2020;
bool cmp(int a,int b)
{
return a > b;
}
int getdecrease(int n)
{
int num[4];
int ans = 0,t=0;
while(n>0)
{
num[t++] = n%10;
n/=10;
}
sort(num,num+4,cmp);
for(int i = 0;i<4;i++)
{
ans = ans * 10 + num[i];
}
return ans;
}
int getincrease(int n)
{
int num[4],ans = 0,t=0;
while(n>0)
{
num[t++] = n%10;
n/=10;
}
sort(num,num+4);
for(int i = 0;i<4;i++)
{
ans = ans * 10 + num[i];
}
return ans;
}
int main()
{
freopen("1.txt","r",stdin);
int n;
scanf("%d",&n);
int a = getdecrease(n);
int b = getincrease(n);
while(1)
{
int c = a - b;
printf("%04d - %04d = %04d\n",a,b,c);
if(c == 6174 || c == 0)
break;
a = getdecrease(c);
b = getincrease(c);
}
return 0;
}
1069 The Black Hole of Numbers (20分)
猜你喜欢
转载自blog.csdn.net/qq_15556537/article/details/104084716
今日推荐
周排行