【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 - 数据库 - Connected to an idle instance
运行 connect /as sysdba; 报错:Connected to an idle instance 原因:配置文件 .bash_profile 中的 ORACLE_HOME 的最后这个 / ...
- pygame 浅解
import pygame from first_pygame.plane_spirit import * # 调用重载的精灵类 # 初始化 pygame.init() # 初始化所有所需游戏模块 s ...
- HihoCoder 1174
虽然没有西加加的语言来检验,我却写了西加加的…… 就是stl使用不太熟练 勉勉强强强行c++写的 就当练手 #include <iostream>#include <vector&g ...
- find & grep 总 结
前言 关于本文 总 结 了 find.grep常 规 用 法,正 则 表 达 式,find与 grep合 用 以 及 自 定 义 搜 索 函 数 等 什么是find和grep find 和 grep ...
- 4.用springboot写的第一个程序--helloworld
这是我自己在controller层建的hello类 运行,选画方框的那个.我查了一晚上,可算知道为啥运行不了了. 然后再浏览器输入网址就ok了 为了大力!好好学习!
- update_jz首项V5.0-Tutorial
What's New: 增加了4个对话框,用于展示信息.归并条目.剔除条目 增加了可视化统计图形中每个科室(柱形)的统计总数 可视化图形一些颜色调整(无奈在省份很多的条件下一些颜色还不易区分) 下面是 ...
- 【C语言】一堆数组中存放了10个小于100的整数,请编程对所有数据按照从小到大的顺序进行排序,若个位数相等,则按照十位从小到大的顺序排序,输出排序后的结果
分析:取余,判断个位是否相等,利用冒泡法排序 #include <stdio.h> int main() { ] = { ,,,,,,,,, };/*数组*/ int i, j, k; ; ...
- 使用VS2015调试Qt5.9.5源码
调试的前提 1.Qt5.9.5源码. 2.Qt5.9.5对应VS2015版本的pdb文件. 前提1在安装Qt时勾选源代码选项即可,这样安装后的Qt目录会多出一个“Src”的目录,里面就是Qt的源码. ...
- python-第三方库的理解及某个函数的源代码
第三方库,是一个总称,里面有各个模块,而具体使用的函数是模块里的. 库包含多个模块, 每个模块里包含多个函数. import AAAA 就是引用AAAA这个库,这个库里的模块函数都可以用,只是 ...
- js实现文字上下滚动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...