PAT (Advanced Level) 1069. The Black Hole of Numbers (20)
简单题。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std; int n;
int a[];
int num1,num2; int f(int num)
{
memset(a,,sizeof a);
int tmp=num;
int z=;
while(tmp) a[z++]=tmp%,tmp=tmp/;
num1=,num2=;
sort(a,a+);
for(int i=;i<;i++) num1=num1*+a[i];
for(int i=;i>=;i--) num2=num2*+a[i];
return num2-num1;
} int main()
{
scanf("%d",&n);
if(f(n)==) printf("%04d - %04d = %04d\n",n,n,);
else
{
while()
{
int res=f(n);
printf("%04d - %04d = %04d\n",num2,num1,res);
n=res;
if(n==) break;
}
}
return ;
}
PAT (Advanced Level) 1069. The Black Hole of Numbers (20)的更多相关文章
- PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642
PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...
- 【PAT甲级】1069 The Black Hole of Numbers (20 分)
题意: 输入一个四位的正整数N,输出每位数字降序排序后的四位数字减去升序排序后的四位数字等于的四位数字,如果数字全部相同或者结果为6174(黑洞循环数字)则停止. trick: 这道题一反常态的输入的 ...
- 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 (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642
PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...
- 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 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) 1065. A+B and C (64bit) (20)
因为会溢出,因此判断条件需要转化.变成b>c-a #include<cstdio> #include<cstring> #include<cmath> #in ...
随机推荐
- mvn 下载源码和javadoc
1. 下载源码,两种: . mvn dependency:sources . mvn eclipse:eclipse -DdownloadSources=true 2. 下载javadoc,两种: . ...
- find排除目录
在linux find 进行查找的时候,有时候需要忽略某些目录不查找,可以使用 -prune 参数来进行过滤,但必须要注意要忽略的路径参数必须紧跟着搜索的路径之后,否则该参数无法起作用. 命令语法: ...
- AngularJS 的表单验证
最近开始学习angularjs,学到表单验证的时候发现有必要学习下大神的好文章: 转:http://www.oschina.net/translate/angularjs-form-validatio ...
- Html wmode 标签参数详解
原文出处:http://blog.sina.com.cn/s/blog_4532d8b50101g2sw.html 在网页中嵌入swf文件时,经常会用到wmode这个参数,而嵌入的swf出现的一些问题 ...
- 遭遇mediumint上限
Mediumint:The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215. home_notific ...
- mysql中AES_ENCRYPT、AES_DNCRYPT及CONVERT的用法
这两天在弄公司的服务端项目的时候,发现mysql比较实用的3个函数,在这里给大家分享一下. 1.AES_ENCRYPT函数,这个函数的使用场景是对一些安全性要求比较高的数据使用AES加密,语法为: A ...
- Ansible6:Playbook简单使用【转】
ansbile-playbook是一系列ansible命令的集合,利用yaml 语言编写.playbook命令根据自上而下的顺序依次执行.同时,playbook开创了很多特性,它可以允许你传输某个命令 ...
- JSP导出Excel后身份证后三位为0
JSP导出Excel身份证号码超出Excel最大限制,用科学计数法表示,但后三位为0,修改方式: <style type="text/css">.txt { ...
- 这几天用到的 Linux 命令
下面总结一下这几天用到的linux 命令,记录一下: 13 netstat -atunlp 26 apt-get install python-pip 27 pip install shadowsoc ...
- c++ 日志操作
程序需要一个简单的日志类,为此简单学习了Boost.Log和google的glog,前者功能非常强大,后者非常小巧但是不够灵活,最终打算自己写一个. 环境: win7 32位旗舰版.VS2010旗舰版 ...