摘要: 输入一个数字n;和一个出栈序列.入栈顺序是从1-n看是否可行..如n=5,出栈序列是1 2 3 4 5,这个可行输出YES 如出栈序列是 5 4 1 2 3 则输出NO#include "stdafx.h"#include#includeusing namespace std;const int MAXN=1000+10;int n,target[MAXN];int _tmain(int argc, _TCHAR* argv[]){ cin>>n; stack s; int A=1,B=1; for(int i =1;i>target[i]; int ok 阅读全文
posted @ 2014-01-14 22:50 CrazyCode. 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 卡片游戏桌面上有一叠牌,从第一张牌开始从上往下一次编号为1-n.当至少还剩下两张牌时进行一下操作:把第一张牌扔掉,然后把新的第一张放到整叠牌的最后。输入n,输出每次扔掉的牌,以及最后剩下的牌。样例输入:7样例输出:1 3 5 7 4 2 6 1 #include "stdafx.h" 2 #include 3 using namespace std; 4 5 int _tmain(int argc, _TCHAR* argv[]) 6 { 7 int num[100]; 8 int inputNum; 9 cin>>inputNum;10 for(int i = 阅读全文
posted @ 2014-01-14 22:09 CrazyCode. 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 假设你有一个各位数字互不相同的四位数,把所有数字从大到小排序后得到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 阅读全文
posted @ 2014-01-14 20:56 CrazyCode. 阅读(502) 评论(0) 推荐(0) 编辑
摘要: 输入补超过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! 阅读全文
posted @ 2014-01-14 18:10 CrazyCode. 阅读(259) 评论(0) 推荐(0) 编辑
摘要: 计算两个整数相加需要多少次进位.?如:输入 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--) { 阅读全文
posted @ 2014-01-14 17:02 CrazyCode. 阅读(99) 评论(0) 推荐(0) 编辑