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. linux基础之Mini Linux制作

    一.编译一个简单的linux步骤如下: # yum groupinstall ""Development Tools" "Server Platform Dev ...

  2. MS SQLServer相关自动化程序的问题汇总 (SQLServer每天定时输出EXCEL或xml的格式的问题等 )

    · MS SQLServer相关问题 1. 使用MS SQLServer每天定时输出EXCEL格式的文件,实现每天的Excel报表导出 2. 使用MS SQLServer每天定时输出xml格式的文件, ...

  3. 使用IntersectionObserver制作滚动动画以及其他记录

    前言 最近在重做公司项目的主页,正好新来了个UI,整个都重新设计了一下,动画还挺多的.我之前没有怎么玩过这些,踩了挺多坑,最后找到了目前而言最合适的方法,现在做一个记录. 需要把原来的主页从项目中抽出 ...

  4. python的优先级

    在编写程序时,我遇到麻烦!怎么找都找不到bug 最终我发现了是我搞错了运算符优先级 位运算要在加减后面(这可真奇怪) eg 10-10^11=11!!! 还是多加括号的好

  5. BZOJ4668 冷战(LCT维护最小生成树)

    BZOJ4668 冷战(LCT维护最小生成树) 题面 自己找去 HINT 这道题就是动态加边,然后查询u,v两点最早什么时候联通,强制在线.思考一下,最早什么时候联通不就等同于维护最小生成树吗(把这条 ...

  6. 设置完代理IP,手机连接WiFi时连不上,一直在转

    fiddler抓包,设置代理后,会出现手机连不上网的情况,针对这个情况处理方式为: 首先如果已经连接上WiFi了,但是提示“不可上网”,那就把WiFi断开重新连接下. 不行的话就试试下面的办法 一.配 ...

  7. kuangbin专题专题十一 网络流 Minimum Cost POJ - 2516

    题目链接:https://vjudge.net/problem/POJ-2516 思路:对于每种商品跑最小费用最大流,如果所有商品和人一起建图跑,O(v^2*m)数量级太大,会超时. 把店里的商品拆点 ...

  8. 微信小程序 获取用户昵称、头像

    前段时间微信小程序对获取用户昵称和头像方法进行了更新,网上很多的文章都已经不适用了,这里简单总结一下,首先,传统接口wx.getUserInfo的效果会弹出一个给用户的弹窗,需要用户授权,经过测试传统 ...

  9. [shell脚本] mysql服务启动脚本

    服务启动脚本(初始化.启动.登录) #!/bin/bash export PID=/usr/local/nestdb_master/bin/mysqld export PASSWORD=123456 ...

  10. linux - mysql - 卸载:RPM包安装方式的MySQL卸载

    (1)检查是否安装了MySQL组件 [root@DB-Server init.d]# rpm -qa | grep -i mysql MySQL-devel-5.6.23-1.linux_glibc2 ...