简单题。

#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)的更多相关文章

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

  2. 【PAT甲级】1069 The Black Hole of Numbers (20 分)

    题意: 输入一个四位的正整数N,输出每位数字降序排序后的四位数字减去升序排序后的四位数字等于的四位数字,如果数字全部相同或者结果为6174(黑洞循环数字)则停止. trick: 这道题一反常态的输入的 ...

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

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

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

  6. 1069 The Black Hole of Numbers (20分)

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

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

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

  9. PAT (Advanced Level) 1065. A+B and C (64bit) (20)

    因为会溢出,因此判断条件需要转化.变成b>c-a #include<cstdio> #include<cstring> #include<cmath> #in ...

随机推荐

  1. YII 常用路径总结

      Yii framework已经定义的命名空间常量 system: 指向Yii框架目录; YII\framework zii: 指向zii library 目录; YII\framework\zii ...

  2. 日期和时间特效-查看"今天是否为节假日"

    ———————————————— <script type="text/javascript">                    function start() ...

  3. jquery为多个元素添加事件

    html <c:forEach items="${modellist}" var="model" varStatus="status" ...

  4. PHP字符串函数试题

    Ctrl+A查看答案 1.把ASCII字符的字符串转换为十六进制值的函数是什么?答:bin2hex($string),例如bin2hex('ab') = 6162 2.ASCII码转字符,字符转ASC ...

  5. shell 中的特殊符号的含义

    来源:http://blog.sina.com.cn/s/blog_62a151be0100x9rn.html 第四章 基本功 - 特殊符号 学习撰写 script 最迅速的捷径是观摩别人的 scri ...

  6. WebRequest 对象的使用

    // 待请求的地址 string url = "http://www.cnblogs.com"; // 创建 WebRequest 对象,WebRequest 是抽象类,定义了请求 ...

  7. STM32F407IG开启FPU,做开方运算

    STM32F407IG开启FPU,做开方运算 MDK KEIL中使用STM32F4XX芯片硬件浮点单元FPU Keil中使用STM32F4xx硬件浮点单元 STM32F4-浮点DSP库的MDK开发环境 ...

  8. 初次stack-overflow 提交答案

    初次在stack-overflow上面提交答案,首先编辑器非常好用,语法检查都有, 还有付费版的,更高级,更好用,nice. 付费版:https://www.grammarly.com/upgrade ...

  9. 01_change_schema.sql

    set echo on feedback on spool ./log/01_change_schema.log -- -- schema change to v_idocdata_un -- -- ...

  10. iOS 2.0 版本切入点

    转载自:http://www.infoq.com/cn/articles/Version_2_0 移动互联网如火如荼,iOS 应用+ Android 应用+ 手机站似乎成了所有互联网公司的标配,你的网 ...