题意:

输入一个四位的正整数N,输出每位数字降序排序后的四位数字减去升序排序后的四位数字等于的四位数字,如果数字全部相同或者结果为6174(黑洞循环数字)则停止。

trick:

这道题一反常态的输入的数字是一个int类型而不是包含前导零往常采用字符串的形式输入,所以在测试点2,3,4如果用字符串输入会超时。。。。。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n;
char x[],y[];
int main(){
scanf("%d",&n);
x[]=n/+'';
n%=;
x[]=n/+'';
n%=;
x[]=n/+'';
n%=;
x[]=n+'';
while(){
if(x[]==x[]&&x[]==x[]&&x[]==x[]){
printf("%s - %s = 0000",x,x);
return ;
}
sort(x,x+);
y[]=x[];
y[]=x[];
y[]=x[];
y[]=x[];
int xx=(x[]-'')*+(x[]-'')*+(x[]-'')*+x[]-'';
int yy=(y[]-'')*+(y[]-'')*+(y[]-'')*+y[]-'';
int zz=yy-xx;
printf("%04d - %04d = %04d",yy,xx,zz);
if(zz==)
break;
else
printf("\n");
x[]=zz/+'';
zz%=;
x[]=zz/+'';
zz%=;
x[]=zz/+'';
zz%=;
x[]=zz+'';
}
return ;
}

【PAT甲级】1069 The Black Hole of Numbers (20 分)的更多相关文章

  1. 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 ...

  2. 1069 The Black Hole of Numbers (20分)

    1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...

  3. 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 ...

  4. 【PAT甲级】1023 Have Fun with Numbers (20 分)

    题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...

  5. 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 inte ...

  6. PAT甲级:1124 Raffle for Weibo Followers (20分)

    PAT甲级:1124 Raffle for Weibo Followers (20分) 题干 John got a full mark on PAT. He was so happy that he ...

  7. 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 ...

  8. PAT (Advanced Level) 1069. The Black Hole of Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT甲题题解-1069. The Black Hole of Numbers (20)-模拟

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789244.html特别不喜欢那些随便转载别人的原创文章又不给 ...

随机推荐

  1. DTU DeepLearning: exercise 7

    torch activation functions: sigmoid, relu, tanh, softplus. https://morvanzhou.github.io/tutorials/ma ...

  2. Java中的IO、NIO、File、BIO、AIO详解

    java中有几种类型的流?JDK为每种类型的流提供了一些抽象类以供继承,请说出他们分别是哪些类?         Java中的流分为两种,一种是字节流,另一种是字符流,分别由四个抽象类来表示(每种流包 ...

  3. Python学习第三天(持续学习了很多的str类型相关方法)

    今天的主要内容是各种各样的str对应方法,就直接把自己测试的东西放在了下面:还有很多习题,这个倒是得抓紧啊. #expandtabs:以制表符\t对字符串进行断句,并根据参数数字补齐位数 test = ...

  4. VMware上Linux虚拟机和Windows共享文件夹

    参考文章:https://blog.csdn.net/qq_19004627/article/details/78689641 操作环境:主机:Windows10,VMware Workstation ...

  5. springboot13(redis缓存)

    redis做springboot2.x的缓存 1.首先是引入依赖 <dependency> <groupId>org.springframework.boot</grou ...

  6. Explainable ML

    定义: 不仅可以(分类),还要输出分类的理由是什么(局部),以及某一个分类的判断标准(全局) 局部: silence map. 把{x1.....xn}中每一个像素加一个偏移量之后,得到的y偏移量与x ...

  7. PHP 可选参数

    function chooseable($a,$b,$d,$c="我是可选参数c"){ //注意:可选参数一定要是在必选参数后面(有默认值就是可选参数):PHP中参数一定要变量符号 ...

  8. 题解【2.23考试T3】val

    3. val[题目描述] 这是一道传统题,源代码的文件名为 val.cpp/c/pas. 有一个值初始为 0,接下来 n 次你可以令其在之前基础上+2 或+1 或-1.你需要保证,这个值在整个过程中达 ...

  9. Game of Credit Cards

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  10. LED Decorative Light Supplier Introduction - LED Track Light Products

    LED Decorative Light Supplier    introduction: LED track light is a track light with LED as the ligh ...