1069.The Black Hole of Numbers
来源:互联网 发布:陈田拆车件市场淘宝 编辑:程序博客网 时间:2024/06/05 17:57
【题意】
求数字黑洞6174的计算过程
【思路】
直接码
【注意点】
若输入的数就是6174也至少要输出一次
#include <cstdio>#include <vector>#include <algorithm>using namespace std;vector<int> num2vec(int num){vector<int> res;res.resize(4);for(int i=3; i>=0; i--){res[i] = num%10;num /= 10;}return res;}int vec2num(vector<int> vec){int num = 0;for(int i=0; i<4; i++){num = num*10+vec[i];}return num;}int main(int argc, char const *argv[]){vector<int> maxNum,minNum;int number;maxNum.resize(4);minNum.resize(4);scanf("%d", &number);minNum = num2vec(number);sort(minNum.begin(),minNum.end());if(minNum[0]==minNum[3]){printf("%d - %d = 0000", number, number);}else{do{maxNum = minNum;reverse(maxNum.begin(),maxNum.end());int max = vec2num(maxNum);int min = vec2num(minNum);number = max-min;printf("%d - %04d = %04d\n", max, min, number);minNum = num2vec(number);sort(minNum.begin(),minNum.end());}while(number!=6174);}system("pause");return 0;}
0 0
- 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)
- 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 (20)
- MySql优化执行语句
- android 项目源码
- Configure with --host, --target and --build options
- 将JSON对象转换成IList,好用linq
- 解决IE下返回json数据提示文件保存到问题
- 1069.The Black Hole of Numbers
- Neural Network实战:Java实现Back Propagation算法 + 手写数字识别
- 1070.Mooncake
- ASP.NET实现验证码记录
- mysql触发器
- R语言学习(二)
- POJ1789 Truck History【Prim】
- DEDE CMS安全警告:Safe Alert: Request Error step 2!
- Java线程:新特征-有返回值的线程