PAT甲题题解-1069. The Black Hole of Numbers (20)-模拟
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~
http://www.cnblogs.com/chenxiwenruo/p/6789244.html
特别不喜欢那些随便转载别人的原创文章又不给出链接的
所以不准偷偷复制博主的博客噢~~
按照题目的意思纯模拟一遍就行了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=;
char str[maxn],str1[maxn],str2[maxn];
int a,b,c;
bool cmp1(char a,char b){
return a>b;
}
bool cmp2(char a,char b){
return a<b;
}
int main()
{
int n;
scanf("%d",&n);
sprintf(str,"%04d",n); //输入的n可能小于4位数,要补0
bool isSame=true;
for(int i=;i<;i++){
if(str[i]!=str[i-]){
isSame=false;
}
}
if(isSame){
printf("%s - %s = 0000\n",str,str);
}
else{
c=;
while(c!=){
//strcpy(str1,str);
//strcpy(str2,str);
sort(str,str+,cmp1);
a=atoi(str);
sort(str,str+,cmp2);
b=atoi(str);
c=a-b;
printf("%04d - %04d = %04d\n",a,b,c);
sprintf(str,"%04d",c); //注意填0
}
}
return ;
}
PAT甲题题解-1069. The Black Hole of Numbers (20)-模拟的更多相关文章
- PAT甲题题解-1065. A+B and C (64bit) (20)-大数溢出
第一眼以为是大数据,想套个大数据模板,后来发现不需要.因为A.B.C的大小为[-2^63, 2^63],用long long 存储他们的值和sum. 接下来就是分类讨论:如果A > 0, B & ...
- 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)【模拟】——PAT (Advanced Level) Practise
题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit inte ...
- 1069 The Black Hole of Numbers (20分)
1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...
- PAT甲题题解-1068. Find More Coins (30)-dp,01背包
一开始没多想,虽然注意到数据N<=10^4的范围,想PAT的应该不会超时吧,就理所当然地用dfs做了,结果最后一组真的超时了.剪枝啥的还是过不了,就意识到肯定不是用dfs做了.直到看到别人说用0 ...
- PAT甲题题解-1008. Elevator (20)-大么个大水题,这也太小瞧我们做题者的智商了
如题... #include <iostream> #include <cstdio> #include <algorithm> #include <cstr ...
- PAT甲题题解-1010. Radix (25)-二分搜索
题意:给出n1和n2,以及其中一个数的进制,问另一个数是多少进制的情况下,才会是两个数相等.不存在的话,则输出Impossible 这题思路很简单,但是要考虑的比较多,在简单题里面算是比较好的. 有两 ...
- PAT甲题题解-1011. World Cup Betting (20)-误导人的水题。。。
题目不严谨啊啊啊啊式子算出来结果是37.975样例输出的是37.98我以为是四舍五入的啊啊啊,所以最后输出的是sum+0.005结果告诉我全部错误啊结果直接保留两位小数就可以了啊啊啊啊 水题也不要这么 ...
- PAT甲题题解-1012. The Best Rank (25)-排序水题
排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...
随机推荐
- MySQL C API 访问 MySQL 示例
代码: /* Simple C program that connects to MySQL Database server */ #include <mysql.h> #include ...
- XtraEditors六、ListBoxControl、CheckedListBoxControl、ImageListBoxControl
ListBoxControl 效果如下: 示例代码: string[] girlArr = { "面码", "Saber", "Mathilda&qu ...
- 博客系统实战——SprintBoot 集成Thymeleaf 实现用户增删查改(含源码)
近来在学习SprintBoot +Thymeleaf +Maven搭建自己的博客系统,故在学习过程中在此记录一下,也希望能给广大正在学习SprintBoot和Thymeleaf的朋友们一个参考. 以下 ...
- Linux第三课——目录操作
ls 列出目录下的文件及子目录 ls -l 以列表的方式显示详细信息 ls -a 显示所有的 包括隐藏文件 ls -A 显示除了 . ..以外的任何文件 ls -i 显示文件的节点号 ls --col ...
- SAP BPC方案介绍
refer to http://sapper.blog.sohu.com/166039991.html SAP/BPC简介: 全面预算管理是联系公司战略目标与日常运营的重要纽带,它上到战略层面.下到执 ...
- JS省市区联动
JS省市区使用文档 一:服务器返回JSON格式要求如下网址里面data的格式:(拿KISSY组件data格式来做的) http://gallery.kissyui.com/cityselector/d ...
- CentOS7.5服务器安装(并添加用户) anaconda3 并配置 PyTorch1.0
===========================================================================================[admin@lo ...
- 前端性能优化:Add Expires headers
前端性能优化:Add Expires headers Expires headers 是什么? Expires headers:直接翻译是过期头.Expires headers 告诉浏览器是否应该从服 ...
- MS SQL Server字符拆分函数
Insus.NET以前有用XQuery的nodes()方法写过一个函数,是MS SQL字符拆分的函数,http://www.cnblogs.com/insus/archive/2012/02/26/2 ...
- 20155202《网络对抗》Exp9 web安全基础实践
20155202<网络对抗>Exp9 web安全基础实践 实验前回答问题 (1)SQL注入攻击原理,如何防御 SQL注入产生的原因,和栈溢出.XSS等很多其他的攻击方法类似,就是未经检查或 ...