【PAT甲级】1069. The Black Hole of Numbers (20)
来源:互联网 发布:淘宝杂货铺好做吗 编辑:程序博客网 时间:2024/06/08 00:04
#include <stdio.h>#include <algorithm>#include <math.h>using namespace std;bool cmp(int a, int b) { return a > b;}int getNum(int *a);int main(int argc, char *argv[]) { int in; int a[4]; scanf("%d", &in); for (int i = 0; i < 4; i++) { a[i] = in / pow(10, 3 - i); in = in % int(pow(10, 3 - i)); } int last = -1; while (true) { int x, y, z; sort(a, a + 4, cmp); x = getNum(a); sort(a, a + 4); y = getNum(a); z = x - y; if (z == last) break; printf("%04d - %04d = %04d\n", x, y, z); last = z; for (int i = 0; i < 4; i++) { a[i] = z / int(pow(10, 3 - i)); z = z % int(pow(10, 3 - i)); } } return 0;}int getNum(int *a) { int rt = 0; for (int i = 0; i < 4; i++) { rt = rt * 10 + a[i]; } return rt;}
阅读全文
0 0
- PAT(甲级)1069. The Black Hole of Numbers (20)
- PAT甲级练习1069. The Black Hole of Numbers (20)
- 【PAT甲级】1069. The Black Hole of Numbers (20)
- PAT 甲级 1069. The Black Hole of Numbers (20)
- [PAT-甲级]1069.The Black Hole of Numbers
- 1019. 数字黑洞 (20)PAT乙级 &1069. The Black Hole of Numbers (20) PAT甲级
- 1069. The Black Hole of Numbers (20)-PAT甲级真题
- PAT 1069. The Black Hole of Numbers
- PAT 1069. The Black Hole of Numbers
- pat 1069. The Black Hole of Numbers
- PAT--1069. The Black Hole of Numbers
- PAT-The Black Hole of Numbers (20)
- 【PAT】1069. The Black Hole of Numbers (20)
- PAT (Advanced) 1069. The Black Hole of Numbers (20)
- PAT A 1069. The Black Hole of Numbers (20)
- PAT 1069. The Black Hole of Numbers (20)
- pat 1069. The Black Hole of Numbers (20)
- PAT 1069. The Black Hole of Numbers (20)
- Android 性能优化(二)
- USACO 虫洞
- git上传本地项目
- LeetCode: 4 Sum
- 好用常用的排序算法
- 【PAT甲级】1069. The Black Hole of Numbers (20)
- Android防止重复点击打开多个页面
- 1.6 实战:自己编译JDK
- 教你轻松面对工作总结
- JavaScript中Null与Undefined的区别
- mysqldump 导出表结构及表数据
- 装饰模式-撤销装饰
- 使用CodeWarrior调试U-Boot
- eclipse 代码迁移到studio上的打包注意情况