1069. The Black Hole of Numbers (20)
来源:互联网 发布:8051 单片机命名 编辑:程序博客网 时间:2024/05/16 02:15
IDEA
1.输入的正整数在(0-10000),如果输入小于4位,则补零补齐4位,在哪个位置没有关系,反正需要排序
2.如果结果为0000或者6174,则循环继续
CODE
#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#include<fstream>using namespace std;int cmp1(int a,int b){return a>b;//降序 }int cmp2(int a,int b){return a<b;//升序 }int isZero(char s[]){for(int i=0;i<4;i++){if(s[i]!='0'){return 0;}}return 1;}int main(){#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);#endifchar s[10000];int a,a1,a2;cin>>s;//小于4位,补零 if(strlen(s)<4){for(int i=strlen(s);i<4;i++){s[i]='0';}s[strlen(s)]='\0';}//如果结果为0000或者6174,则循环继续 while(!isZero(s)&&(a1-a2)!=6174) {a1=0;a2=0;sort(s,s+4,cmp1);cout<<s<<" - ";int j=3;for(int i=0;i<4;i++){a1+=(s[i]-'0')*pow(10,j--);}sort(s,s+4,cmp2);cout<<s<<" = ";j=3;for(int i=0;i<4;i++){a2+=(s[i]-'0')*pow(10,j--);}a=a1-a2;for(int i=3;i>=0;i--){s[i]=a%10+'0';a/=10;}cout<<s<<endl;}#ifndef ONLINE_JUDGEfclose(stdin);#endifreturn 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)
- 怎么在Beyond Compare中快速同步文件夹的
- 浅析安全自动化编排平台Phantom
- list去掉重复数据
- apk增量更新
- LeetCode Excel Sheet Column Number(进制转换问题)
- 1069. The Black Hole of Numbers (20)
- android studio文件名颜色说明
- RedHat Enterprise Linux 5/6 ISO镜像下载
- 【oracle】查找字符串的位置 instr
- 随笔:tab标签随手势左右滑动的渐变效果,类似微信
- JQ-DOM操作-1
- VS error C2664 转换错误汇总
- [FFmpeg-user] ERROR: libass not found using pkg-config
- istream_iterator和ostream_iterator使用