【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特别不喜欢那些随便转载别人的原创文章又不给 ...
 
随机推荐
- [BJOI2012]连连看
			
Description Luogu4134 Solution \(l,r \le 1000\),暴力枚举是否能匹配.这是一个选匹配的问题,所以直接网络流,原图不一定是二分图咋办?拆点啊!然后直接做就行 ...
 - Python中的模块简单认识
			
将自己定义的方法,变量存放在文件中,为一些脚本或者交互式的解释器实例使用,这个文件称为模块. 细说的话,模块可以分为四个通用类别: 1 使用python编写的.py文件(自定义模块) 2 已被编译为共 ...
 - python面试的100题(8)
			
企业面试题 15.python新式类和经典类的区别? (在Python 2及以前的版本中,由任意内置类型派生出的类(只要一个内置类型位于类树的某个位置),都属于“新式类”,都会获得所有“新式类”的特性 ...
 - 经常犯的错误之递归写不全return
			
在写递归函数的时候,只在最后一层写return,中间的过程没有return,导致结果的丢失. 举个例子 LL query(LL i, LL k) { if (sum[i] < k) { ; } ...
 - crontab调用python脚本新思路
			
crontab调用python脚本文件,有可能失败,定时执行并没有执行,怎么办? 答:写一个shell脚本调用python,然后用crontab调用shell脚本.具体细节,有时间补充. ————— ...
 - Python | 字符串拆分和拼接及常用操作
			
一.字符串拆分 str = "hola ha1 ha2 china ha3 " # partition 从左侧找到第一个目标,切割成三组数据的[元组] str1 = str.par ...
 - zabbix监控规划及实施
			
一.规划监控拓扑 二.主机分组 例:交换机.Nginx.Tomcat.MySQL 三.监控对象识别: 1.使用SNMP监控交换机 a.交换机开启snmp config -t snmp-server c ...
 - 线程池(ExecutorService)初体验
			
背景:查询月统计数据,因为查询日统计数据功能已经实现.月统计数据,只是参一个List(date) 参数,for循环调用日统计,然后把结果整合就OK. 问题:单线程跑 太耗时间 解决方案:使用多线程, ...
 - xhr 的 onpregress 监听上传数据的  已上传  和 总大小
			
var fd=new FormData(); $('.mwd_uppingzheng_btna_ok').on('click',function () { // 数组转 str var strarr= ...
 - 使用Eclipse远程调试云服务器上的微信公众项目
			
云服务器系统:centos 7.3 如何在Eclipse上调试我们在云服务器上的项目呢,下面介绍一下步骤: 1.因为root账号不支持远程调试,首先需要在linux上创建一个新的用户,然后用该用户 ...