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

2010年9月24日

摘要: #include "stdafx.h" #include double Power(double base, int exp) { std::bitset bits(exp); int numOf1 = bits.count(); double tempResult[32]; for(int i=0;i<32;i++) tempResult[i] = 1.0; int coun... 阅读全文

posted @ 2010-09-24 20:33 KurtWang 阅读(387) 评论(0) 推荐(0) 编辑

摘要: // 100_46.cpp : Defines the entry point for the console application. // #include "stdafx.h" int find_len(char * str) { if(str==NULL) return 0; int len = 1; char * cur = str; while(*str!='\0') ... 阅读全文

posted @ 2010-09-24 20:18 KurtWang 阅读(447) 评论(0) 推荐(0) 编辑

摘要: // 100_42.cpp : Defines the entry point for the console application. // #include "stdafx.h" int find(int * arr, int left, int right) { if(left==right-1) return arr[right]; int mid = (left+right)... 阅读全文

posted @ 2010-09-24 20:05 KurtWang 阅读(258) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" #include void bottom(std::stack& s, int t) { if(s.empty()) s.push(t); else { int temp = s.top(); s.pop(); bottom(s,t); s.push(temp); } } void reverse(std::stack& s... 阅读全文

posted @ 2010-09-24 19:40 KurtWang 阅读(440) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" void print(char * number, int len, int index) { if(index == len) { printf("%s\n",number); return; } for(int i=0;i<10;i++) { number[index] = '0' + i; print(number, len... 阅读全文

posted @ 2010-09-24 19:30 KurtWang 阅读(213) 评论(0) 推荐(0) 编辑

摘要: // 100_37.cpp : Defines the entry point for the console application. // #include "stdafx.h" long ugly(long index) { long * uglyNum = new long[index]; uglyNum[0] = 1; long next = 1; long * p2 = u... 阅读全文

posted @ 2010-09-24 19:15 KurtWang 阅读(259) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" #include #include void del(char * str1, const char * str2) { assert(str1); assert(str2); int count[256] = {0}; for(int i=0;i<strlen(str2);i++) count[str2[i]-'\0']++; ch... 阅读全文

posted @ 2010-09-24 18:49 KurtWang 阅读(256) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" int find_first_1(int n) { int index = 1; while( (n&1)==0 && index >= 1; index <<= 1; } return index; } void find(int * arr, int len, int & num1, int & num2) { int temp = 0;... 阅读全文

posted @ 2010-09-24 18:34 KurtWang 阅读(428) 评论(2) 推荐(0) 编辑

摘要: // 100_31.cpp : Defines the entry point for the console application. // #include "stdafx.h" struct Node { Node * next; int value; }; void print(Node * head) { if(!head) return; if(head->next... 阅读全文

posted @ 2010-09-24 17:24 KurtWang 阅读(264) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" bool isEven(int n) { return (n&1) == 0; } void reorder(int * arr, int len) { int * begin = arr; int * end = arr+len-1; while(true) { while(!isEven(*begin)) { begin++;... 阅读全文

posted @ 2010-09-24 17:20 KurtWang 阅读(249) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" void permutation(char * str, char * begin) { if(!str || !begin) return; if(*begin == '\0') printf("%s\n",str); else { for(char * cur = begin; *cur != '\0'; cur++) { ... 阅读全文

posted @ 2010-09-24 17:09 KurtWang 阅读(176) 评论(0) 推荐(0) 编辑

摘要: // 100_27.cpp : Defines the entry point for the console application. // #include "stdafx.h" struct Node { Node * left; Node * right; int value; }; int depth(Node * root) { if(!root) return 0;... 阅读全文

posted @ 2010-09-24 16:56 KurtWang 阅读(216) 评论(0) 推荐(0) 编辑

摘要: // 100_26.cpp : Defines the entry point for the console application. // #include "stdafx.h" void find(int n) { int small = 1; int big = 2; int middle = (n+1)/2; int sum = small + big; while(sm... 阅读全文

posted @ 2010-09-24 16:51 KurtWang 阅读(169) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" #include int LCS(const char * str1, const char * str2) { if(str1 == NULL || str2 == NULL) return -1; int len1 = strlen(str1); int len2 = strlen(str2); if(len1 LCS[i][j-1])... 阅读全文

posted @ 2010-09-24 16:28 KurtWang 阅读(244) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" struct Node { Node * next; int value; }; Node * reverse(Node * head) { if(!head) return NULL; Node * prev = NULL; Node * cur = NULL; Node * curNext = head; while(curNext... 阅读全文

posted @ 2010-09-24 16:13 KurtWang 阅读(223) 评论(0) 推荐(0) 编辑

摘要: // 100_15.cpp : Defines the entry point for the console application. // #include "stdafx.h" int fibo1(int n) { if(n==0) return 0; else if(n==1) return 1; int f0=0; int f1=1; int f2; for(... 阅读全文

posted @ 2010-09-24 15:45 KurtWang 阅读(346) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h" void find(char * str, size_t len) { int count[256] = {0}; for(int i=0;i<len;i++) count[str[i]-'\0']++; for(int i=0;i<len;i++) if(count[str[i]-'\0']==1) { printf("%c\n... 阅读全文

posted @ 2010-09-24 14:56 KurtWang 阅读(210) 评论(0) 推荐(0) 编辑

摘要: // 100_12.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include struct Node { Node * left; Node * right; int value; }; void visit(Node * root) { if(!root) ... 阅读全文

posted @ 2010-09-24 14:47 KurtWang 阅读(256) 评论(0) 推荐(0) 编辑

摘要: // 100_11.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include struct Node { Node * left; Node * right; int value; }; void mirror(Node * root) { if(root==... 阅读全文

posted @ 2010-09-24 14:41 KurtWang 阅读(152) 评论(0) 推荐(0) 编辑

摘要: // 100_6.cpp : Defines the entry point for the console application. // #include "stdafx.h" bool verify(int * arr, int len) { if(arr == NULL || len root) break; } int j=i; for(;j0) left = v... 阅读全文

posted @ 2010-09-24 13:21 KurtWang 阅读(201) 评论(0) 推荐(0) 编辑