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. VMware桥接模式下虚拟机ping主机不通

    现象: VMware设置为桥接模式,虚拟机ping主机不通,主机ping虚拟机通. 解决: 尝试以下几种方法 关闭主机(专用网络.来宾或公用网络)和虚拟机的防火墙. 更改桥接的物理网卡,确保是主机正在 ...

  2. 【29】带你了解计算机视觉(Computer vision)

    计算机视觉(Computer vision) 计算机视觉是一个飞速发展的一个领域,这多亏了深度学习. 深度学习与计算机视觉可以帮助汽车,查明周围的行人和汽车,并帮助汽车避开它们. 还使得人脸识别技术变 ...

  3. 二分类模型之logistic

    liner classifiers 逻辑回归用在2分类问题上居多.它是一个非线性的回归模型,其最大的好处恰恰是可以解决二元类问题,目前在金融行业,基本都是使用Logistic回归来预判一个用户是否为好 ...

  4. jQuery Moblie 问题汇总

    1  使用jQuery动态添加html,没有jQuery Moblie的样式 $("body").html(listview);//以上代码只是把结构加上去了,但是却没有加上jqm ...

  5. ubuntu16.04更换成国内源

    一.首先使用自带的vi编辑器 安装完ubuntu后没有默认的root密码,如果要设置root密码需要进行如下步骤: 1 sudo passwd 2 连续输入两次新密码 二.vi编辑器下使用[backs ...

  6. pytest+requests+Python3.7+yaml+Allure+Jenkins+docker实现接口自动化测试

    接口自动化测试框架(用例自动生成) 项目说明 本框架是一套基于pytest+requests+Python3.7+yaml+Allure+Jenkins+docker而设计的数据驱动接口自动化测试框架 ...

  7. 剑指offer 56.删除有序链表中的重复结点

    56. 删除有序链表中的重复结点 题目描述 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3-> ...

  8. windows-problem :电脑上网的无线图标带有黄色星号,但不影响正常上网!

    电脑可以上网,但是无线图标带有黄色星号如何解决? 进入“网络和共享中心”,点击“更改适配器设置”,看看是不是有两个以上的“本地连接”,只有一个有用,其他的删除即可.

  9. 机器学习作业(五)机器学习算法的选择与优化——Matlab实现

    题目下载[传送门] 第1步:读取数据文件,并可视化: % Load from ex5data1: % You will have X, y, Xval, yval, Xtest, ytest in y ...

  10. HTTPClient模拟Get和Post请求

    一.模拟Get请求(无参) 首先导入HttpClient依赖 <dependency> <groupId>org.apache.httpcomponents</group ...