题意:

输入一个四位的正整数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 分)的更多相关文章

  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. 1069 The Black Hole of Numbers (20分)

    1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...

  3. 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 ...

  4. 【PAT甲级】1023 Have Fun with Numbers (20 分)

    题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

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

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

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

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

随机推荐

  1. COMMUNITY DETECTION_python-louvain

    Python-louvain Package pip install python-louvain import community #first compute the best partition ...

  2. Linux异常 时间戳 2018-10-08 11:17:22 是未来的 5288025.776562967 秒之后

    原因:系统时间不对,有可能落后当前实际时间

  3. ORA-00917: missing comma

    问题描述 ORA-00917: missing comma 问题原因 逗号,引号什么的多了或者少了,或者换行引起的

  4. SpringBoot开发快速入门

    SpringBoot开发快速入门 目录 一.Spring Boot 入门 1.Spring Boot 简介 2.微服务 3.环境准备 1.maven设置: 2.IDEA设置 4.Spring Boot ...

  5. jsp中的javascript的$(document).ready( function() { $("#loginForm").validate()

    转自:https://bbs.csdn.net/topics/392459787?list=71147533 下面是jsp页面中的JavaScript代码 $(document).ready( fun ...

  6. maven报错Non-resolvable parent POM---pom找不到parent

    没有配置relativePath属性,说明运行的时候使用的是默认的,所以它会在默认的pom父类中查找,而不会到我自己创建的里面进行寻找 参考链接:https://blog.csdn.net/qq_37 ...

  7. Vue+ElementUI重置表单数据至初始值

    https://blog.csdn.net/linjingke32/article/details/99446403

  8. 用python实现密码校验程序

    密码需要符合下面的要求: 8个字符以上,包含数字,大小写,开头不能为特殊字符. #! /usr/bin/pythonimport re password = str(input()) def lenO ...

  9. wamp选择语言

    桌面右下角 右击绿色小图标 点击language选择chinese

  10. 解决async 运行多线程时报错RuntimeError: There is no current event loop in thread 'Thread-2'

    原来使用: loop = asyncio.get_event_loop()task = asyncio.ensure_future(do_work(checker))loop.run_until_co ...