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. 深入理解Java内存模型中的虚拟机栈

    深入理解Java内存模型中的虚拟机栈 Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干个不同的数据区域,这些区域都会有各自的用途,以及创建和销毁的时间,有的区域会随着虚拟机进程的启 ...

  2. PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  3. 替换 MyEclipse 中已有的项目

    一.删除 tomcat 中的项目 1.停止 tomcat 2.删除 tomcat 中的项目 选中项目,然后右键 - Remove deployment,这个可能需要一点时间 二.删除 MyEclips ...

  4. 题解 AT1812 【テレビ】

    题目大意 高桥君有一个宽\(w\),高\(h\)的电视机. 判定\(w:h\)是\(4:3\)还是\(16:9\). 分析 我们可以理解成把一个比\(w:h\)化为最简整数比,也就是将\(w:h\)化 ...

  5. linux 搭建python虚拟环境

    requirements.txt 包含paramiko,pysfp.setuptools,适用python版本3.6.6+ 前提编译安装python wget wget https://www.pyt ...

  6. NPOI 生成Excel

    private void btnSave_Click(object sender, EventArgs e) { ) != ".xls") { MessageBox.Show(&q ...

  7. LeetCodeTwo Sum IV 树的遍历+Hash大法好

    题意 给定一颗二叉搜索树,返回是否存在两个节点的值之和为给定值K. 思路 同Two Sum.使用Hash表解决.只是要写个树的遍历而已,选取DFS. 源码 class Solution { publi ...

  8. webservice后台起调试

    https://blog.csdn.net/smile00_0/article/details/72763114

  9. Supervision meeting with Liu

    data stream;streampipe/nifi data flow:1. algorithm;;;; top-k pattern, motif and so on 2. implication ...

  10. PHP 实现微信小程序敏感图片、内容检测接口

    主要是为了调用微信小程序msgSecCheck.imgSecCheck接口. 先附上小程序接口说明文档地址:https://developers.weixin.qq.com/miniprogram/d ...