1069 The Black Hole of Numbers (20分)

1. 题目

2. 思路

把输入的数字作为字符串,调用排序算法,求最大最小

3. 注意点

输入的数字的范围是(0, 104), 如果作为字符串处理时要注意前面补0

4. 代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; bool cmp(char a, char b){
return a>b;
} int main(){
int n;
scanf("%d", &n);
char a[5];
sprintf(a, "%04d", n);
int max, min;
sort(a, a+4, cmp);
sscanf(a, "%d", &max);
sort(a, a+4);
sscanf(a, "%d", &min);
if(max == min){
printf("%04d - %04d = 0000", max, min);
}else{
int value = max - min;
while(value != 6174){
printf("%04d - %04d = %04d\n", max, min, value);
sprintf(a, "%04d", value);
sort(a, a+4, cmp);
sscanf(a, "%d", &max);
sort(a, a+4);
sscanf(a, "%d", &min);
value = max - min;
}
printf("%04d - %04d = %04d", max, min, value);
}
return 0;
}

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. 【PAT甲级】1069 The Black Hole of Numbers (20 分)

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

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

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

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

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

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

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

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

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

  9. PAT 1069 The Black Hole of Numbers

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

随机推荐

  1. 手写数字识别——基于LeNet-5卷积网络模型

    在<手写数字识别——利用Keras高层API快速搭建并优化网络模型>一文中,我们搭建了全连接层网络,准确率达到0.98,但是这种网络的参数量达到了近24万个.本文将搭建LeNet-5网络, ...

  2. 关于c# hashtable的一个注意点

    Hashtable在操作时,一定要注意一点: 当保存值时,如果使用的是字符串作为键,那么在判断是否存在此键时,必须使用字符串来检查,否则,即使是能隐式转换的值也将无法检查到,如: Hashtable ...

  3. 曼孚科技:AI语音交互领域常用的4个术语

    ​语音交互是基于语音输入的新一代交互模式,比较典型的应用场景是各类语音助手. 本文整理了语音交互领域常用的4个术语,希望可以帮助大家更好地理解这门学科. 1. 语音合成标记语言(SSML) 语音合成标 ...

  4. ros下怎么查看usb设备在哪个端口

    检查usb设备是否有权限以及在哪个端口,或者lsusb ls -l /dev |grep ttyUSB 查到设备端口,在启动文件下配置相应的端口号 <param name="seria ...

  5. 《图解HTTP》笔记

    web网络基础 概述 Web是建立在HTTP(超文本传输协议)上通信的 通常使用的网络(包括互联网)是在TCP/IP基础上运作的,HTTP属于它的内部子集 TCP/IP协议 协议族 计算机与网络设备要 ...

  6. 【笔记0-开篇】面试官系统精讲Java源码及大厂真题

    背景 开始阅读 Java 源码的契机,还是在第一年换工作的时候,被大厂的技术面虐的体无完肤,后来总结大厂的面试套路,发现很喜欢问 Java 底层实现,即 Java 源码,于是我花了半年时间,啃下了 J ...

  7. nodepad++ | 变成 _

    点击右下角切换

  8. 曼孚科技:AI自然语言处理(NLP)领域常用的16个术语

    ​自然语言处理(NLP)是人工智能领域一个十分重要的研究方向.NLP研究的是实现人与计算机之间用自然语言进行有效沟通的各种理论与方法. 本文整理了NLP领域常用的16个术语,希望可以帮助大家更好地理解 ...

  9. yum装包报错

    [root@iZ6wefn2kl6064uuaxuwetZ ~]# yum –y install  gcc  pcre-devel zlib-devel openssl-develLoaded plu ...

  10. 记录 Docker 的学习过程 (网络篇之跨主机互通)

    下面从node3上操作node3# docker run -d -p 8500:8500 --name consul progrium/consul -server -bootstrap node3# ...