题意:

输入一个四位的正整数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. flask入门(二)

    接着上文 讲一讲响应 flask调用视图函数后,会将其返回值作为响应的内容.大多数情况下,响应就是一个简单的字符串,作为HTML页面回送客户端.但HTTP协议需要的不仅是作为请求响应的字符串.HTTP ...

  2. VSFTPD服务器

    我虽然vsftpd服务器做了百遍以上,但是我觉的成功率不大.我要写下这篇日记,来让我分析自己曾经的过错!! vsftpd的原理我不多讲!!!请自行百度吧!! 我搭建的环境是 Linux6.4 IP(1 ...

  3. mvc 模板位置

    mvc4 模板位置 Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates mvc5 模板位置 Common7\IDE\Extensions\ ...

  4. Java学习笔记(十一)面向对象---多态

    多态的体现 父类的引用指向了自己的子类对象. 父类的引用也可以接受自己的子类对象. 代码体现 abstract class Animal { public abstract void eat(); } ...

  5. 慎用--skip-grant-tables命令

    该命令作用是跳过授权表,也就是说谁都能进入mysql看到所有数据表,输入任意字符账号密码都可以 当忘记账号密码时可以使用改命令修改密码,但是要随用随关,重启mysql,不然服务器上会有很大的风险. 介 ...

  6. linux-zookeeper安装、配置

    1.下载zookeeper包 (地址:https://www-eu.apache.org/dist/zookeeper/) 2.上传zookeeper包到指定位置(例如: /usr/local/sof ...

  7. redis源码(八)redis-check-aof.c

    /* * Copyright (c) 2009-2012, Pieter Noordhuis <pcnoordhuis at gmail dot com> * Copyright (c) ...

  8. vmware Linux虚拟机挂载共享文件夹

    本文主要是记录vmware linux虚拟机如何挂载共享文件夹过程,以备不时之需. 设置允许共享文件夹 1. 启用共享文件夹 [VM]->[settings]->[Options]-> ...

  9. Flink架构(二)- Flink中的数据传输

    2. Flink中的数据传输 在一个运行的application中,它的tasks在持续交换数据.TaskManager负责做数据传输.TaskManager的网络组件首先从缓冲buffer中收集re ...

  10. 7.log4j

    Log4j:日志工厂的一部分(使用起来比较麻烦) 1.要想使用外部类,得先导包 pom.xml <dependency> <groupId>log4j</groupId& ...