简单题。

#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. Table隔行变色的JavaScript代码

    <table id="datatable"> <tr> <td>脚本之家</td> </tr> <tr> & ...

  2. zencart低版本由php5.2.17升级PHP5.3环境下错误及解决方案

    方法:有错误或者空白先打开错误提示,ftp看cache错误日志 或者 面板查看错误日志,再对比数据库是否正确,可拿脚本看是否能连接 \cp -r  backipmysql/nlbarb_007li/ ...

  3. getTime 方法

    转自http://www.yesky.com/imagesnew/software/javascript/html/jsmthgettime.htm getTime 方法返回 Date 对象中的时间值 ...

  4. login/logout切换

    1. 前端按钮 <img border="0" width="18" height="18" src="<%=base ...

  5. JSP精华知识点总结

    本文转自:http://blog.csdn.net/qy1387/article/details/8050239 JSP精华知识点总结 Servlet三个要素 1.必须继承自HttpServlet 2 ...

  6. 巧妙利用ToArray()函数移除集合中的元素

    当我们对集合foreach遍历时,不能直接移除遍历的集合的元素,解决的方法有很多种,见我之前的随笔: http://www.cnblogs.com/527289276qq/p/4331000.html ...

  7. java中的类修饰符、成员变量修饰符、方法修饰符

    类修饰符:  public(访问控制符),将一个类声明为公共类,他可以被任何对象访问,一个程序的主类必须是公共类. abstract,将一个类声明为抽象类,没有实现的方法,需要子类提供方法实现. fi ...

  8. LightOJ 1058 平行四边形的判断定理

    题目大意:给你n个点,求这n个点最多能组成多少个平行四边形. 题目思路:这道题卡时间,而且卡内存.你要尽可能的想办法优化. 平行四边形的判定定理: 两组对边分别平行的四边形是平行四边形(定义判定法): ...

  9. boost库之geometry<二>

    #include <boost/assign.hpp> #include <boost/geometry/core/point_type.hpp> #include <b ...

  10. easyui easyui-filebox 显示中文

    <input class="easyui-filebox" name="uploadFile" id="uploadFileid" d ...