【PAT甲级】1069 The Black Hole of Numbers (20 分)
题意:
输入一个四位的正整数N,输出每位数字降序排序后的四位数字减去升序排序后的四位数字等于的四位数字,如果数字全部相同或者结果为6174(黑洞循环数字)则停止。
trick:
这道题一反常态的输入的数字是一个int类型而不是包含前导零往常采用字符串的形式输入,所以在测试点2,3,4如果用字符串输入会超时。。。。。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n;
char x[],y[];
int main(){
scanf("%d",&n);
x[]=n/+'';
n%=;
x[]=n/+'';
n%=;
x[]=n/+'';
n%=;
x[]=n+'';
while(){
if(x[]==x[]&&x[]==x[]&&x[]==x[]){
printf("%s - %s = 0000",x,x);
return ;
}
sort(x,x+);
y[]=x[];
y[]=x[];
y[]=x[];
y[]=x[];
int xx=(x[]-'')*+(x[]-'')*+(x[]-'')*+x[]-'';
int yy=(y[]-'')*+(y[]-'')*+(y[]-'')*+y[]-'';
int zz=yy-xx;
printf("%04d - %04d = %04d",yy,xx,zz);
if(zz==)
break;
else
printf("\n");
x[]=zz/+'';
zz%=;
x[]=zz/+'';
zz%=;
x[]=zz/+'';
zz%=;
x[]=zz+'';
}
return ;
}
【PAT甲级】1069 The Black Hole of Numbers (20 分)的更多相关文章
- 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 ...
- 1069 The Black Hole of Numbers (20分)
1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...
- 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 ...
- 【PAT甲级】1023 Have Fun with Numbers (20 分)
题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...
- 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 ...
- PAT甲级:1124 Raffle for Weibo Followers (20分)
PAT甲级:1124 Raffle for Weibo Followers (20分) 题干 John got a full mark on PAT. He was so happy that he ...
- 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 ...
- PAT (Advanced Level) 1069. The Black Hole of Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲题题解-1069. The Black Hole of Numbers (20)-模拟
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789244.html特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- 第五十三篇 Linux相关——Web服务器
No.1. Apache基本操作 安装:sudo yum -y install httpd 启动:service httpd start 停止:service httpd stop 查看服务运 ...
- AcWing 794. 高精度除法
https://www.acwing.com/problem/content/796/ #include<bits/stdc++.h> using namespace std; // A/ ...
- AcWing 789. 数的范围 二分+模板
https://www.acwing.com/problem/content/791/ #include<bits/stdc++.h> using namespace std; ; int ...
- Android 获取手机的厂商、型号、Android系统版本号等工具类(转载)
Android 获取手机的厂商.型号.Android系统版本号等工具类 1.获取手机制造厂商 2.获取手机型号 3.获取手机系统当前使用的语言 4.获取Android系统版本号 5.获取手机IMEI串 ...
- ansible笔记(6):常用模块之系统模块
1.cron模块 cron命令是计划任务功能,与crontab功能类似. 示例:时间格式--->>>分 时 日 月 星期 10 12 27 * * tar -cvzf log ...
- SFSA
#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #in ...
- phpstudy扩展mongoDB
观察如下3个参数,即位数,ts/nts,vc9/vc11/……三条规则(一定要一一对应) 重要是,还要对应PHP的版本,我选的是5.6的对应的版本 去http://windows.php.net/do ...
- Unity Coroutine详解(二)
• 介绍• Part 1. 同步等待• Part 2. 异步协程• Part 3. 同步协程• Part 4. 并行协程 1.介绍 ...
- PyCharm中的django项目的引入
1.从github或者从本地的文件打开项目 2.项目引入后,python manage.py runserver 8080启动 1.启动的时候有错误,看看要引入的模块错误,然后把模块引入 D:\.St ...
- [Vue源码]一起来学Vue双向绑定原理-数据劫持和发布订阅
有一段时间没有更新技术博文了,因为这段时间埋下头来看Vue源码了.本文我们一起通过学习双向绑定原理来分析Vue源码.预计接下来会围绕Vue源码来整理一些文章,如下. 一起来学Vue双向绑定原理-数据劫 ...