PAT-A1069. The Black Hole of Numbers (20)(数学)
来源:互联网 发布:sql语句中系统时间 编辑:程序博客网 时间:2024/06/03 20:11
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std;int a[4];void toArray(int n){int k = 0;memset(a, 0, sizeof(a));while (n){a[k++] = n%10;n /= 10;}} int toNum(){int x = 0;for (int i = 3; i >= 0; i--){int n = pow(10,3-i) + 0.5;x += a[i] * n;}return x;}int cmp_a(const void *a, const void *b){return *(int*)a - *(int*)b;}int cmp_d(const void *a, const void *b){return *(int*)b - *(int*)a;}int main(){//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);int n = 0, sub = 0, num1 = 0, num2 = 0;scanf("%d", &n);toArray(n);while (true){qsort(a, 4, sizeof(int), cmp_d);num1 = toNum();qsort(a, 4, sizeof(int), cmp_a);num2 = toNum();sub = num1 - num2;printf("%04d - %04d = %04d\n", num1, num2, sub);if (sub == 0 || sub == 6174)break;toArray(sub);}return 0;}
0 0
- PAT-A1069. The Black Hole of Numbers (20)(数学)
- pat-a1069. The Black Hole of Numbers (20)
- PAT A1069. The Black Hole of Numbers (20)
- PAT A1069 the black hole of numbers (20)
- A1069 . The Black Hole of Numbers (20)
- PAT-The Black Hole of Numbers (20)
- PAT(甲级)1069. The Black Hole of Numbers (20)
- 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】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)
- PAT 1069. The Black Hole of Numbers (20)
- git的使用
- jsp/servlet中 forward, include, reDirect 之间的区别
- PAT-B1003. 我要通过!(20)(数学)
- Cygwin config
- GuideMap 登陆界面 详细文档(二)
- PAT-A1069. The Black Hole of Numbers (20)(数学)
- ORACLE RAC(11203)环境将误建立在本地目录的文件转移到ASM存储中
- BZOJ4008/HNOI2015 亚瑟王(期望dp)
- Adb failed to restart! Make sure the plugin is properly configured.
- PAT-A1008. Elevator (20)
- 环境变量配置文件
- Windows 2008环境SharePoint无法上传大文件的解决方案
- PAT-A1049. Counting Ones (30)
- android日常开发总结技术60条