摘要:
假设你有一个各位数字互不相同的四位数,把所有数字从大到小排序后得到a,从小到大排序后得到b,然后用a-b替换原来这个数,并且继续操作。例如:从1234出发,依次可得到4321-1234=3087 8730-378=8352 8532-2358=6174。有趣的是 7641-1467=6174.回到了它自己.输入一个n位数,输出操作序列,直到出现循环为止(即新得到的数曾经得到过).输入保证在循环之前最多只会产生1000个整数.样例输入:1234样例输出:1234->3087->8352->6174->6174#include "stdafx.h"#in 阅读全文
摘要:
输入补超过1000的正整数n,输出n!=1*2*3....*n的精确结果..样例输入:30样例输出:265252859812191058636308480000000 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 const int maxn=3000; 6 int f[maxn]; 7 int _tmain(int argc, _TCHAR* argv[]) 8 { 9 int i ,j,n;10 cin>>n;11 f[0]=1;12 for(int k = 1;k! 阅读全文
摘要:
计算两个整数相加需要多少次进位.?如:输入 123 456 /555 555/ 123 594输出 0 3 1#include "stdafx.h"#includeusing namespace std; int _tmain(int argc, _TCHAR* argv[]){ int a,b; while(cin>>a&&cin>>b) { if(!a&&!b) return 0;//如果输入都是0的话.程序中断退出. int c = 0,ans = 0; for(int i = 9;i>=0;i--) { 阅读全文