PAT_1069. The Black Hole of Numbers
来源:互联网 发布:php分割价格函数 编辑:程序博客网 时间:2024/06/05 06:20
#include <iostream>#include <algorithm>#include <string.h>using namespace std;int N,num[4];int cmp(int a,int b){return a>b;}bool PrepareAndJudge(){memset(num,0,sizeof(num));int j=0,temp=N;while(temp!=0){num[j]=temp%10;temp/=10;j++;}for(int i=1;i<4;i++){if(num[i]!=num[0])return true;}return false;}int Trans(){int A[4],B[4],C[4];for(int i=0;i<4;i++)A[i]=B[i]=num[i];sort(A,A+4,cmp);for(int i=0;i<4;i++)printf("%d",A[i]);printf(" - ");sort(B,B+4);for(int i=0;i<4;i++)printf("%d",B[i]);printf(" = ");for(int i=3;i>=0;i--){if(A[i]-B[i]>=0)C[i]=A[i]-B[i];else{A[i-1]--;C[i]=A[i]+10-B[i];}}int result = 0;for(int i=0;i<4;i++){result = result*10+C[i];printf("%d",C[i]);}printf("\n");for(int i=0;i<4;i++)num[i]=C[i];return result;}int main(){scanf("%d",&N);if(PrepareAndJudge()==false)printf("%d - %d = 0000",N,N);else{while(1){if(Trans()==6174)break;}}return 0;}
这题之前做过,所以很快就解决了。
阅读全文
0 0
- PAT_1069. The Black Hole of Numbers
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers
- PAT 1069. The Black Hole of Numbers
- PAT 1069. The Black Hole of Numbers
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers
- 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
- 1069. The Black Hole of Numbers (20)
- pat1069 The Black Hole of Numbers
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- mysql 日期时间格式化
- EasyUI主题切换
- Map中的TreeMap根据value排序
- centos配置firewall
- java基础-事务
- PAT_1069. The Black Hole of Numbers
- Linux的EXT2文件系统详解
- java根据map指定的value值获取对应的key值使用Gson实现
- xml不同状态的显示
- 动态规划——求最长公共子序列(和子串)长度
- 0816JS
- 关于适配器纹波噪声与主板纹波噪声的问题分析
- caffe Reshape layer 使用
- Git 常用操作