博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2010年9月23日

摘要: #include "stdafx.h" //N阶乘末尾有多少个0 int question1(int n) { int ret = 0; while(n) { n /= 5; ret += n; } return ret; } //N阶乘的二进制表示中最低位1的位置 int question2(int n) { int ret =0; while(n) { n >... 阅读全文

posted @ 2010-09-23 19:33 KurtWang 阅读(197) 评论(0) 推荐(0)

摘要: // 2_9.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #define INT_MIN -100000 //最大值和最小值 void min_max(int * arr, size_t len, int & min, int &max) { asse... 阅读全文

posted @ 2010-09-23 19:31 KurtWang 阅读(1677) 评论(0) 推荐(0)

摘要: #include "stdafx.h" //辗转相除法的改良版,因为取摸开销大,所以改用减法,然后利用是否都是偶数的性质,做优化 int gcd(int a, int b) { if(a>1,b>>1)*2; else return gcd(a>>1,b); } else { if(b&1==0) return gcd(a,b>>1); else ... 阅读全文

posted @ 2010-09-23 17:02 KurtWang 阅读(473) 评论(0) 推荐(0)

摘要: // 2_4.cpp : Defines the entry point for the console application. // #include "stdafx.h" long sum1s(long n) { long count =0; long factor = 1; long lower = 0; long cur = 0; long higher = 0; ... 阅读全文

posted @ 2010-09-23 15:59 KurtWang 阅读(490) 评论(0) 推荐(0)

摘要: #include "stdafx.h" int find(int * ID, int N) { int cand; int nTimes=0; for(int i=0;i<N;i++) { if(nTimes == 0) { cand = i; nTimes = 1; } else { if(cand == ID[i]) nTimes++; ... 阅读全文

posted @ 2010-09-23 14:52 KurtWang 阅读(585) 评论(1) 推荐(1)

摘要: #include "stdafx.h" int count(int t) { int ret = 0; while(t) { t &= t-1; ret++; } return ret; } int _tmain(int argc, _TCHAR* argv[]) { printf("%d\n",count(1)); printf("%d\n",count(2)); p... 阅读全文

posted @ 2010-09-23 14:45 KurtWang 阅读(242) 评论(0) 推荐(0)

2010年9月22日

摘要: // 3_10.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include struct Node { int data; Node * left; Node * right; }; int printByLevel(Node * root, int level) { if(!root || level data); return ... 阅读全文

posted @ 2010-09-22 22:46 KurtWang 阅读(256) 评论(0) 推荐(0)

摘要: #include "stdafx.h" #include struct Node { Node * left; Node * right; char value; }; void Rebuild(char * pPreOrder, char * pInOrder, int nTreeLen, Node ** root) { assert(pPreOrder); assert(pIn... 阅读全文

posted @ 2010-09-22 22:23 KurtWang 阅读(298) 评论(0) 推荐(0)

摘要: #include "stdafx.h" const int MAXN = 100; class stack { public: stack() { stackTop = -1; maxItemIndex = -1; } void Push(int x) { stackTop ++; if(stackTop >= MAXN) ; else { item... 阅读全文

posted @ 2010-09-22 20:23 KurtWang 阅读(783) 评论(0) 推荐(0)

摘要: #include "stdafx.h" struct Node { int value; Node * next; }; //判断是否有环,返回bool,如果有环,返回环里的节点 bool isCircle(Node * head, Node *& circleNode, Node *& lastNode) { Node * fast = head->next; Node * slow... 阅读全文

posted @ 2010-09-22 18:57 KurtWang 阅读(908) 评论(0) 推荐(0)