随笔分类 -  笔试&&面试

摘要:分段K-M-P 只需要记录上一段已经匹配了的长度,再接着从匹配下一段就可以了。 阅读全文
posted @ 2013-09-17 19:35 l851654152 阅读(189) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include using namespace std;struct foo{ char d;};struct s{ int x:3;int y:4;int z:5;double a;};#include void main(){ int N; cin >> N; float x= 1.0; float x0; float f; float f1; do { x0 = x; f = x0 * x0 - N; f1 = 2 * x0; x = x0- f/f1; } while (fabs(x 阅读全文
posted @ 2013-09-17 15:24 l851654152 阅读(209) 评论(0) 推荐(0)
摘要:templatebool matrixFind(T (*array)[5], int n, const T & val){int i = n-1, j = 0;while(i>=0 && j val){i--;}else if(a[i][j] < val){j++;}else{return true;}}return false;} 阅读全文
posted @ 2013-09-16 22:33 l851654152 阅读(105) 评论(0) 推荐(0)
摘要:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->voidprintSList(slist*pList){assert(pList);if(pList==NULL)return;if(pList->next==NULL)printf("%s",*pList);else{printSList(pList->next);printf("%s",*pList);}}以后遇到尽可能少的关键字就会想到递 阅读全文
posted @ 2013-09-15 14:45 l851654152 阅读(141) 评论(0) 推荐(0)
摘要:vector:1.当插入(push_back)一个元素后,end操作返回的迭代器肯定失效。2.当插入(push_back)一个元素后,capacity返回值与没有插入元素之前相比有改变,则需要重新加载整个容器,此时first和end操作返回的迭代器都会失效。3.当进行删除操作(erase,pop_back)后,指向删除点的迭代器全部失效;指向删除点后面的元素的迭代器也将全部失效。deque迭代器的失效情况:1.在deque容器首部或者尾部插入元素不会使得任何迭代器失效。2.在其首部或尾部删除元素则只会使指向被删除元素的迭代器失效。3.在deque容器的任何其他位置的插入和删除操作将使指向该容器 阅读全文
posted @ 2013-09-14 09:44 l851654152 阅读(235) 评论(0) 推荐(0)
摘要:typedef int NUM[10];//声明整型数组类型NUM n;//定义n为整型数组变量,其中n[0]--n[9]可用加typedef是类型,不加是变量 阅读全文
posted @ 2013-09-14 00:39 l851654152 阅读(172) 评论(0) 推荐(0)
摘要:由于c没有重载 c++有重载,c++翻译名字时通过函数名+参数,加extern “c”是采用c调用方式,从而链接正确的函数。 阅读全文
posted @ 2013-09-13 23:56 l851654152 阅读(191) 评论(0) 推荐(0)
摘要:/* return 1 if string contain only digits, else return 0 */ int valid_digit(char *ip_str) { while (*ip_str) { if (*ip_str >= '0' && *ip_str = 0 && num <= 255) { /* parse remaining string */ ptr = strtok(NULL, DELIM); if (ptr != NULL) ... 阅读全文
posted @ 2013-09-13 22:43 l851654152 阅读(6090) 评论(0) 推荐(0)
摘要:1. 楼梯有n个台阶,上楼可以一步上1阶,也可以一步上2阶,一共有多少种上楼的方法?斐波那契数列 第一项为1 第二项为2 也就是f(n)=f(n-1)+f(n-2),用递归求。给个分析的例子:有一个11级的台阶,一个人可走一步也可走两步,问这个人有多少种方法走完这个台阶?解:①只用一步走:1+1+1+1+1+1+1+1+1+1+1=11,共11步,只有C11,1=1种走法。②用了一次两步走:1+1+1+1+1+1+1+1+1+2=11,共10步,有C10,1 =10种走法。③用了两次两步走:1+1+1+1+1+1+1+2+2=11,共9步,有C9,2 =36种走法。④用了三次两步走:1+1+. 阅读全文
posted @ 2013-09-13 22:16 l851654152 阅读(10256) 评论(1) 推荐(2)
摘要:有81匹马,9个赛道,问至少比赛多少次可以取跑的最快的前四名?可以这么考虑,先赛九场,可得到每场最快的马,再将这九匹每组最快的马再赛一次,得到跑的最快的马,然后踢出最快的马,并将踢出的马所在的那组第二快的马补上,再将赛这九匹马,然后踢出最快的马,此时踢出的马为全部马中第二快的马,依次类推,所以总共要赛9+4=13次。 阅读全文
posted @ 2013-09-13 21:28 l851654152 阅读(373) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include using namespace std;bool cmp(int a,int b){ return a>b;}int main(){ int n; cin >>n; int num[65536]={0}; for (int i = 1;i 0) { count++; } } cout << count <<endl; return 0;} 阅读全文
posted @ 2013-09-12 23:08 l851654152 阅读(137) 评论(0) 推荐(0)
摘要:算法#include #include #include #include #include #include using namespace std;bool cmp(int a,int b){ return a>b;}int main(){ int num[10]; for (int i = 0;i>num[i]; } sort(num,num+10,cmp); int i = 0; for (i = 0;i<10;i++) { if (num[i] <= 60) { break; } } if (i==10) { cout << "60&qu 阅读全文
posted @ 2013-09-12 22:31 l851654152 阅读(146) 评论(0) 推荐(0)
摘要://strcmp(const char *src,const char *dst)int __cdecl strcmp (const char * src,const char * dst){int ret = 0 ;while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst && *src)++src, ++dst;if ( ret < 0 )ret = -1 ;else if ( ret > 0 )ret = 1 ;return( ret );} 阅读全文
posted @ 2013-06-04 09:55 l851654152 阅读(128) 评论(0) 推荐(0)
摘要:public static int find(int[] array) { int size = array.length; int result = 0;// 需要查找的结果 int times = 0;// 出现的次数 for (int i = 0; i < size; i++) { // 如果次数等于0,重新指定结果 if (times == 0) { result = arr... 阅读全文
posted @ 2013-04-08 22:52 l851654152 阅读(187) 评论(0) 推荐(0)
摘要:View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 typedef struct Lode{ 5 int elem; 6 struct Lode *pnext; 7 }LNODE, *List; 8 9 /**10 **创建一个链表11 **/12 void CreateList(List &L,int n)13 {14 L = (struct Lode*)malloc(sizeof(List));15 L->pnext = NULL;16 17 int num;18 f... 阅读全文
posted @ 2012-09-07 21:28 l851654152 阅读(197) 评论(0) 推荐(0)
摘要:View Code 1 #include <stdlib.h> 2 #include <string.h> 3 #include <stdio.h> 4 void Reverse(char *pbegin,char *pend) 5 { 6 char temp; 7 while(pbegin < pend) 8 { 9 temp = *pbegin;10 *pbegin = *pend;11 *pend = temp;12 pbegin++;13 pend--;14 }15 }16... 阅读全文
posted @ 2012-09-06 23:24 l851654152 阅读(163) 评论(0) 推荐(0)
摘要:View Code 1 #include <stdio.h> 2 bool VerifySquenceBST(int *Squence,int length) 3 { 4 if(Squence == NULL || length <= 0) return false; 5 int root = Squence[length - 1]; 6 for(int i = 0;i < length-1;++i) 7 { 8 if(Squence[i] > root) break; 9 }10 int j = i;11 for(;j... 阅读全文
posted @ 2012-09-06 22:51 l851654152 阅读(218) 评论(0) 推荐(0)
摘要:View Code 1 int FindPath(BITREE T,int key,int &cursum,std::vector<int>& vec) 2 { 3 if(!T) return 0; 4 cursum += T->elem; 5 vec.push_back(T->elem); 6 7 bool isLeaf = (!T->lchild && !T->rchild); 8 9 if(key == cursum && isLeaf)10 {11 vector<int>::iterator 阅读全文
posted @ 2012-09-06 21:07 l851654152 阅读(216) 评论(0) 推荐(0)
摘要:View Code 1 #include <stdio.h> 2 3 int main() 4 { 5 int subsum = 0; 6 int great = 0; 7 int a[8] = {1,-2,3,10,-4,7,2,-5}; 8 for(int i = 0;i < 8;i++) 9 {10 subsum = subsum + a[i];11 if(subsum < 0) subsum = 0;12 if(subsum > great)13 {14 ... 阅读全文
posted @ 2012-09-06 20:32 l851654152 阅读(126) 评论(0) 推荐(0)
摘要:http://www.cppblog.com/Joe/category/16955.htmlhttp://www.cppblog.com/menjitianya/archive/2011/05/26/147205.htmlhttp://www.cnblogs.com/sopc-mc/archive/2011/10/28/2228179.htmlhttp://www.cppblog.com/Joe/archive/2011/05/25/147091.html?opt=admin 阅读全文
posted @ 2012-09-06 14:35 l851654152 阅读(113) 评论(0) 推荐(0)