
C/C++
lwl_ls
这个作者很懒,什么都没留下…
展开
-
KMP
void KMP_MatcherJ(char *T, int nt, char *p, np){ int i,k; int *x=new int[np+1]; // because p[] begins at index 1 PrefixFun(p, np, x); k=0; for(i=1;i while(k>0 && p[k+1]!=T[i]) k=x[k];原创 2007-12-03 10:56:00 · 738 阅读 · 0 评论 -
srand and rand
luowenlong@im-vm07:~/code$ vi srand.cpp/* srand example */#include #include #include int main (){ for(int i = 0; i printf ("First number: %d/n", rand() % 100);/* srand ( time(NULL) ); print原创 2010-05-11 21:19:00 · 779 阅读 · 0 评论 -
一致性hash服务器调整影响面的概率分析
负载均衡 一致性哈希 consistent hashing原创 2010-06-08 19:40:00 · 611 阅读 · 0 评论 -
window下,include支持/和\, mac只认/
空原创 2011-09-16 10:44:04 · 664 阅读 · 0 评论 -
linux mac列出目录下的文件和文件夹名字
#include #include #include int main(int argc, char *argv[]){ if(argc < 3){ printf("argc error\n"); return -1; } DIR *pCu原创 2011-09-21 18:26:41 · 1307 阅读 · 0 评论 -
UIInterfaceOrientation
plist的设置,会覆盖代码里的设置。即,如果代码写- (BOOL)shouldAutorotate{ return NO;}但是plist里UIInterfaceOrientationPortraitUIInterfaceOrientationPortraitUpsideDownUIInterfaceOrientationLand原创 2013-02-03 20:50:30 · 656 阅读 · 0 评论 -
sunpinyin出词调用顺序
-(BOOL)handleEvent:(NSEvent*)event client:(id)sender SunPinyinInputController.mm=>CSunpinyinSessionWrapper::bool onKeyEvent(const CKeyEvent& event)=>boolCIMICla原创 2013-02-06 17:24:58 · 1076 阅读 · 0 评论 -
CGRect的width为nan时导致界面异常
if(FileStatusReceiveNew == self.model.status || 0 == self.model.fileProgressLength) self.model.progress = 0; // self.model.progress = nan会导致下面一行绘制界面时界面出异常, 无法push FileViewerViewController. 点击该原创 2013-05-02 14:40:32 · 1092 阅读 · 0 评论 -
svn import后,服务器上少了所有*.a文件的问题解决
将本地代码import到svn服务器。svn co出代码,编译却报错少了这个那个*.a文件,手动添加这些*.a文件极其麻烦。*.a文件丢失的原因:svn有个默认的global-ignores列表,会忽略那些不常用的文件,如:*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.pyc *.pyo *.rej *~ #*# .原创 2014-03-01 16:26:55 · 8918 阅读 · 0 评论 -
hash_map构造函数设与不设初始bucket数的区别
根据hash_map的实现进行理论猜测,不设初始bucket数时,插入是会比较慢的。实际测试证实如果设置合适的初始bucket数效率较高,快1倍左右。 ============================================ 不设初始bucket数时 #include #include #include using namespace __gnu_原创 2010-04-25 15:47:00 · 1215 阅读 · 0 评论 -
gcj 08 r1A-large
#include#includeusing namespace std;inline int cmp (const void *a, const void *b){ long long aa = *(long long *)a; long long bb = *(long long *)b; return (aa bb) ? 1 : 0;}v原创 2009-08-30 21:49:00 · 564 阅读 · 0 评论 -
google code jam 08 资格赛A题
#include#include#includeusing namespace std;const int hash_size = 199;unsigned int ELFHash( char * str) { unsigned int hash = 0 ; unsigned int x = 0 ; whi原创 2009-08-30 19:47:00 · 654 阅读 · 0 评论 -
linux上的C/C++编译器gcc/egcs详解
linux上的C/C++编译器gcc/egcs详解转载 2008-02-25 08:17:00 · 985 阅读 · 0 评论 -
sizeof with base class
#include iostream>#include cstring>using namespace std;class A...{public: A():c(2)...{}; // c : must be initialized in constructor base/member initializer list int getC()...{ return c;原创 2007-12-17 15:16:00 · 661 阅读 · 0 评论 -
Big number multiplication 大整数乘法
const int N=1100;struct BigNum...{ int front; int data[N+1];};BigNum& Mulit(BigNum up, BigNum down)...{ int i,k,carry,v; BigNum prod; prod.front=up.front+down.front-N+1; for(i=prod.front;iN;i+原创 2008-01-05 09:25:00 · 1294 阅读 · 0 评论 -
Fibonacci相关题目
请分别设计一个递归和非递归算法来计算F(n) F列可递归定义为: n为大于等于0的整数 F(n)=n 当n=0,1,2 F(n)=F(n-1) - F(n-3) 当n>=3 const int Max=1000000;bool got[Max];int gotVal[Max];int Cal(int原创 2008-01-12 09:49:00 · 724 阅读 · 0 评论 -
没有合适的默认构造函数可用
#include "stdafx.h"#includeiostream>using namespace std;class A...{public: static void OutOK()...{ cout"A ok"endl; }};class B...{public: B()...{ cout"construct B"endl; }原创 2008-01-16 11:01:00 · 7844 阅读 · 2 评论 -
C++派生继承中的一个问题!
#include "iostream.h"class A...{public: int num; A()...{ num = 1; } virtual void Display()...{ cout "A"; } void print()...{转载 2008-04-27 00:46:00 · 685 阅读 · 1 评论 -
MaxSection 最长平台
#includeusing namespace std;int MaxSection(int *a, int n){ int max,i,sum; max=-200000000; sum=0; for(i=0;i sum=sum+a[i]; if(sum>max) max=sum; if(sum } return max;}void main(){ int a[]={2,2,3,原创 2008-05-03 19:33:00 · 777 阅读 · 0 评论 -
C++中的explicit
简而言之:explicit修饰的构造函数不能担任类型转换函数这个 《ANSI/ISO C++ Professional Programmers Handbook 》是这样说的explicit ConstructorsA constructor that takes a single argument is, by default, an implicit conversion operator,原创 2008-05-03 10:34:00 · 811 阅读 · 0 评论 -
头文件与extern
>>>>为何定义不应该放头文件: 由下面关于编译模块(单元)的定义可知,如果f1.c,f2.cpp均include了a.h,则a.h中的变量或函数定义,会被编译到f1.o,f2.o中,链接时导致重复定义的错误。2008/12/30 lwl lwl.roger@gmail.com>:> 2008/12/30 lwl lwl.roger@gmail.com>:>> 可以这样的理解:>>>>>> 编原创 2009-01-01 22:49:00 · 1118 阅读 · 1 评论 -
[设计模式]状态模式
一、状态模式的特点:>改变对象内部的状态来帮助对象控制自己的行为>每个状态的行为都封装在各自的类中>动作发生时委托给当前状态>每个状态”对修改关闭”; context(对象)”对扩展开放”,可以加入新的状态类二、何时用状态模式:1. 逻辑里有各种状态。一般是超过3个以上状态2. 状态是关于某个对象或上下文(context)的3. 好几个地方需要判断if条件原创 2015-06-24 13:18:10 · 852 阅读 · 0 评论