1069 The Black Hole of Numbers (20分)

1. 题目

2. 思路

把输入的数字作为字符串,调用排序算法,求最大最小

3. 注意点

输入的数字的范围是(0, 104), 如果作为字符串处理时要注意前面补0

4. 代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; bool cmp(char a, char b){
return a>b;
} int main(){
int n;
scanf("%d", &n);
char a[5];
sprintf(a, "%04d", n);
int max, min;
sort(a, a+4, cmp);
sscanf(a, "%d", &max);
sort(a, a+4);
sscanf(a, "%d", &min);
if(max == min){
printf("%04d - %04d = 0000", max, min);
}else{
int value = max - min;
while(value != 6174){
printf("%04d - %04d = %04d\n", max, min, value);
sprintf(a, "%04d", value);
sort(a, a+4, cmp);
sscanf(a, "%d", &max);
sort(a, a+4);
sscanf(a, "%d", &min);
value = max - min;
}
printf("%04d - %04d = %04d", max, min, value);
}
return 0;
}

1069 The Black Hole of Numbers (20分)的更多相关文章

  1. PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

  2. 【PAT甲级】1069 The Black Hole of Numbers (20 分)

    题意: 输入一个四位的正整数N,输出每位数字降序排序后的四位数字减去升序排序后的四位数字等于的四位数字,如果数字全部相同或者结果为6174(黑洞循环数字)则停止. trick: 这道题一反常态的输入的 ...

  3. 1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise

    题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit inte ...

  4. PAT 1069. The Black Hole of Numbers (20)

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  5. 1069. The Black Hole of Numbers (20)

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  6. PAT Advanced 1069 The Black Hole of Numbers (20) [数学问题-简单数学]

    题目 For any 4-digit integer except the ones with all the digits being the same, if we sort the digits ...

  7. PAT (Advanced Level) 1069. The Black Hole of Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. PAT甲题题解-1069. The Black Hole of Numbers (20)-模拟

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789244.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  9. PAT 1069 The Black Hole of Numbers

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

随机推荐

  1. css样式的兼容性

    浏览器                 前缀 IE和safari             -webkit- Chrome                -ms- Firefox            ...

  2. Building a Space Station POJ - 2031 三维最小生成树,其实就是板子题

    #include<iostream> #include<cmath> #include<algorithm> #include<cstdio> usin ...

  3. 订阅消息---由于微信小程序取消模板消息,限只能开发订阅消息

    订阅消息开发步骤: 1.小程序管理后台添加订阅消息的模板 2.小程序前端编写调用(拉起)订阅授权 wx.requestSubscribeMessage({ tmplIds: ['34fwe1211xx ...

  4. BDA3 Chapter 1 Probability and inference

    1. uncertainty aleatoric uncertainty 偶然不确定性 epistemic uncertainty 认知不确定性 2. probability VS likelihoo ...

  5. SpringBoot之spring.factories

    组件提供者如何编写出仅需系统开发者进行包引入就可以对spring进行bean注入等操作?   其实在spring库中有提供自动化配置的库spring-boot-autoconfigure,我们只需要引 ...

  6. 【巨杉数据库SequoiaDB】企业级和开源领域“两开花”,巨杉引领国产数据库创新

    2019年12月15日,OSC 源创会·年终盛典在深圳圆满举行.巨杉数据库作为业界领先的金融级分布式数据库厂商, 获得 “2019年开源数据库先锋企业” 及 “2019 GVP-Gitee最有价值开源 ...

  7. UVa - 12050 Palindrome Numbers (二分)

    Solve the equation: p ∗ e −x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x 2 + u = 0 where 0 ≤ x ≤ ...

  8. Eclipse中配置Tomcat容器

    Tomcat 安装与配置 Tomcat是Apache 软件基金会(Apache Software Foundation)核心项目之一,支持最新的Servlet 和JSP 规范.因为Tomcat 技术先 ...

  9. Linux C/C++ 字符串逆序

    /*字符串逆序*/ #include <stdio.h> #include <string.h> void nixu(char *str) { ; char tmp; for( ...

  10. 还不错的Table样式和form表单样式

    作为一个后台开发人员而言,拥有一套属于自己的前台样式是比较重要的,这里分享一下自己感觉还不错的样式,以后遇到好的,还会陆续添加 上图: 带鼠标滑动效果的table样式看起来比较清爽 样式 <he ...