1069 The Black Hole of Numbers (20分)
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分)的更多相关文章
- 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 ...
- 【PAT甲级】1069 The Black Hole of Numbers (20 分)
题意: 输入一个四位的正整数N,输出每位数字降序排序后的四位数字减去升序排序后的四位数字等于的四位数字,如果数字全部相同或者结果为6174(黑洞循环数字)则停止. trick: 这道题一反常态的输入的 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- PAT (Advanced Level) 1069. The Black Hole of Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲题题解-1069. The Black Hole of Numbers (20)-模拟
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789244.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 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 ...
随机推荐
- C#实例之简单聊天室(状态管理)
前言 状态管理是在同一页或不同页的多个请求发生时,维护状态和页信息的过程.因为Web应用程序的通信协议使用了无状态的HTTP协议,所以当客户端请求页面时,ASP.NET服务器端都会重新生 ...
- Java设计模式(四)工厂方法模式
定义与类型 定义:定义一个创建对象的接口,但让实现这个接口的类来决定实例化哪个类,工厂方法让类的实例化推迟到子类中进行. 类型:创建型 适用场景 创建对象需要大量重复的代码 客户端(应用层)不依赖于产 ...
- 性能优化 && 用户体验
性能优化 下拉菜单那种最好是点击时候请求,或者是查询时候请求 分页加载 用户体验 有加载.进度条.友好提示
- js替换时,空格被替换为双引号
替换代码 str.replace(/\"/g, "'") 将双引号替换为单引号,如果字符串中,存在space(空格)时,使用以上语句将会导致空格被替换为双引号,可以使用如 ...
- 深入理解Java内存模型中的虚拟机栈
深入理解Java内存模型中的虚拟机栈 Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干个不同的数据区域,这些区域都会有各自的用途,以及创建和销毁的时间,有的区域会随着虚拟机进程的启 ...
- ECMAScript基本语法——⑤运算符 逻辑运算符
&&与,会短路:左边为false右边就不参与运算||或,会短路:左边为true右边就不参与运算!非, 注意:在JavaScript中,如果运算数不是运算符要求的类型,那么JavaScr ...
- 仿ios按钮切换
<div> <label><input class="btn-switch" type="checkbox"> 默认未选中& ...
- day03_1spring3
事务管理的几种方式.spring整合Junit.spring整合web.ssh整合 一.事务管理的几种方式: 1.介绍前提我们需要导入:spring-tx-3.2.0.RELEASE.jar的包里面含 ...
- java打印出某一指定路径下的文件夹内的所有子文件夹和文件,并区分开来
public class printoutFile { public static void main(String[] args) { printFile(new File("D:\\te ...
- 查看Spark与Hadoop等其他组件的兼容版本
安装与Spark相关的其他组件的时候,例如JDK,Hadoop,Yarn,Hive,Kafka等,要考虑到这些组件和Spark的版本兼容关系.这个对应关系可以在Spark源代码的pom.xml文件中查 ...