1069.The Black Hole of Numbers (20)
来源:互联网 发布:mba有用吗 知乎 编辑:程序博客网 时间:2024/05/17 09:10
1069.The Black Hole of Numbers (20)
pat-al-1069
2017-01-27
- 乙级就写过这题,这次再写就优化了一下
- 排序直接使用了sort
- 使用sprintf和sscanf进行字符串和数字之间的转换
- 坑见注释
/** * pat-al-1069 * 2017-01-27 * Cpp version * Auhtor: fengLian_s */#include<iostream>#include<stdio.h>#include<vector>#include<algorithm>using namespace std;bool cmp1(char a, char b){ return a > b;}bool cmp2(char a, char b){ return a < b;}int main(){ int n; scanf("%d", &n); char num[5];//坑:4的话会出错 sprintf(num, "%04d", n);//坑:注意格式控制 //printf("n = %d\n", n); do { int max, min; sprintf(num, "%04d", n); //printf("n = %d\n", n); if(num[0] == num[1] && num[0] == num[2] && num[0] == num[3]) { printf("%d - %d = 0000\n", n, n); return 0; } sort(num, num+4, cmp1); //printf("num = %s\n", num); sscanf(num, "%d", &max); //cout << "max = " << max << endl; sort(num, num+4, cmp2); sscanf(num, "%d", &min); //cout << "min = " << min << endl; n = max - min; printf("%04d - %04d = %04d\n", max, min, n); } while(n != 6174);}
-FIN-
0 0
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- eclipse从SVN检出maven web项目
- HDU-3397-Sequence operation
- Linux相关文章索引(3)
- 计算组合数 (sdut oj)
- 快速理解 FastCGI、PHP-CGI、PHP-FPM
- 1069.The Black Hole of Numbers (20)
- graph Laplacian 拉普拉斯矩阵
- 感知机
- 补间动画调用了VIEW哪些函数?
- 我为什么不看好微信小程序
- hdu 1860
- 我为什么不看好微信小程序_0
- [140328]ALIA’s CARNIVAL! +ALIA’s CARNIVAL! Flowering Sky【日文硬盘版】[带全CG存档]
- recv函数和readline实现思想