1069. The Black Hole of Numbers (20)
来源:互联网 发布:动态桌面软件怎么设置 编辑:程序博客网 时间:2024/05/16 18:54
#include <string>#include<algorithm>#include <vector>#include <sstream>#include <iostream>using namespace std;bool cmp1(char a,char b){return a>b;}bool cmp2(char a,char b){return a<b;}int a,b;stringstream ss,ss1,ss2;void solve(int n){ss.clear();string s2="",s3="";string s1="";string s4="";int c=1000;int d; for(int i=0;i<4;i++) { if(n/c==0) s1+='0'; else{ d=n/c;string tmp=""; ss.clear(); ss<<d; ss>>tmp; s1+=tmp;} n=n%c; c/=10; }vector<char>v1,v2;for(int i=0;i<4;i++){v1.push_back(s1[i]);v2.push_back(s1[i]);}sort(v1.begin(),v1.end(),cmp1);sort(v2.begin(),v2.end(),cmp2);for(int i=0;i<4;i++){s2+=v1[i];s3+=v2[i];}ss1.clear();ss2.clear();ss1<<s2;ss2<<s3;ss1>>a;ss2>>b;}int main(){ int n;cin>>n;if(n==0)printf("0000 - 0000 = 0000");else{solve(n);while(a-b!=6174&&a-b!=0){ printf("%.4d - %.4d = %.4d\n",a,b,a-b);solve(a-b);}printf("%.4d - %.4d = %.4d\n",a,b,a-b);}return 0;}
0 0
- 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)
- 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)
- 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)
- 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)
- 1069. The Black Hole of Numbers (20)
- 1069. The Black Hole of Numbers (20)
- Tomcat:IOException while loading persisted sessions: java.io.EOFException
- 兼容各个浏览器的H.264播放: H.264+HTML5+FLOWPLAYER+WOWZA+RMTP
- websphere 修改内存配置信息
- 中断服务程序ISR
- STM32待机模式学习笔记
- 1069. The Black Hole of Numbers (20)
- iOS7新特性 ViewController转场切换(二) 系统视图控制器容器的切换动画---push pop present dismis
- 指针数组和数组指针问题 分析的不错
- presto初探【0.52版本】
- cocos2d-x在android下添加插屏广告 .
- Python中的logging模块就这么用
- 直播评测:电视家2.x
- POJ 2159 Ancient Cipher
- 你想读留学读计算机博士吗?先看看这篇文章