PAT 1069. The Black Hole of Numbers (20)
2015-11-23 17:40
531 查看
#include<vector> #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<queue> #include<map> #include<stack> using namespace std; #define INF 100000000 #define min(a,b) a<b?a:b void chang(int a[],int n) { a[0]=n/1000; a[1]=(n%1000)/100; a[2]=(n%100)/10; a[3]=n%10; } int main() { int n; int a[6],l,m; int t=0; l=m=0; scanf("%d",&n); int s=6174; chang(a,n); sort(a,a+4); if(a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3]) printf("%d - %d = %04d\n",n,n,t); else { while(l-m!=s) { l=a[0]+a[1]*10+a[2]*100+a[3]*1000; m=a[0]*1000+a[1]*100+a[2]*10+a[3]; printf("%04d - %04d = %04d\n",l,m,l-m); chang(a,l-m); sort(a,a+4); } } return 0; }
相关文章推荐
- 关于Bitmap的recycle()的理解
- Python中的类方法和静态
- 第十二周 - 纸上谈兵 - 图的广度深度及矩阵
- 微信开发遇到的坑
- MVC实现类似QQ的网页聊天功能-Ajax(上)
- PowerShell生成随机密码
- nginx 安装&配置监听端口
- PowerShell生成随机密码
- Oracle Interval-Partition 解决Range分区大难题
- 经典面试题--FizzBuzz的面向对象版本
- C++中重载、重写(覆盖)和隐藏的区别
- ios图片加水印或文字
- swift 1.0更新为2.0后的变化
- word 标题序号
- Android屏幕适配经验谈
- 集成JAX-RS和JSON-P
- Cordova webapp archive时候 报错 Cordova/CDVViewController.h f 4000 ile not found
- cordova学习笔记
- linux安装sz rz工具记
- Android开发屏幕适配全攻略