PAT1069. The Black Hole of Numbers

//这是到水题,之前因为四位数的原因一直不能A,看了别人的程序,才明白,不够四位的时候没考虑到,坑啊。。。。。脸打肿

#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
//freopen("input.txt","r",stdin);
int i,n,s[5];
while(scanf("%d",&n)!=EOF)
{
while(1)
{
int len=0;
fill(s,s+4,0);
for(i=0;i<4;i++)
{
s[3-i]=n%10;
n/=10;
}
sort(s,s+4);
int n1=0,n2=0;
for(i=0;i<4;i++)
{
n1=n1*10+s[i];
n2=n2*10+s[4-1-i];
}
n=n2-n1;
printf("%04d - %04d = %04d\n",n2,n1,n);
if(n==0||n==6174)break;
}
}
return 0;
}

时间: 2024-12-28 13:39:04

PAT1069. The Black Hole of Numbers的相关文章

pat1069. The Black Hole of Numbers (20)

1069. The Black Hole of Numbers (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-

PAT 1069. The Black Hole of Numbers (20)

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in

1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise

题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new n

PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

1069 The Black Hole of Numbers (20 分) For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second

The Black Hole of Numbers (strtoint+inttostr+sort)

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in

1069. The Black Hole of Numbers

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in

1069. The Black Hole of Numbers (20)

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in

PAT Advanced 1069 The Black Hole of Numbers (20分)

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in

PAT:1069. The Black Hole of Numbers (20) AC

#include<stdio.h> #include<algorithm> using namespace std; const int AIM=6174; int n; int arr[4]; bool NonIncreasingOrder(int a,int b) { return a>b; } bool NonDecreasingOrder(int a,int b) { return a<b; } int toNum() //得到这个数字 { int sum=0;