摘要:
题目一: [cpp] view plaincopy void GetMemory( char *p ) { p = (char *) malloc( 100 ); } void Test( void ) { char *str = NULL; GetMemory( str ); strcpy( str, "hello world" ); printf( str ... 阅读全文
摘要:
1 #include 2 #include 3 #include 4 using namespace std; 5 6 void TransformExpr(char *oldexpr,char *newexpr) 7 { 8 stack s; 9 int i=0; 10 int j=0; 11 while(oldexpr[i] != '\0') 12... 阅读全文
摘要:
1 int N = 3; 2 int V = 5; 3 int C[4] = {0,1,2,3}; 4 int W[4] = {0,60,100,120}; 5 int f[N][V]; 6 //memset(f,0,sizeof(int)*N*V); 7 for(int i=0;i (f[i-1][j-C[i]]+W[i])? f[i-1][j]:(f[i-1][j-C[i]]+... 阅读全文
摘要:
1 namespace AStuff{ 2 template 3 class A 4 { 5 public: 6 void swap(A *other) 7 { 8 using std::swap; 9 swap(pImpl,other.plmpl); 10 } 11 private: 12 AImpl *pImpl; 13 }; 14 template 15 void sw... 阅读全文
摘要:
1 void Permutation(char* pStr, char* pBegin) 2 { 3 assert(pStr && pBegin); 4 5 if(*pBegin == '\0') 6 printf("%s\n",pStr); 7 else 8 { 9 for(char* pCh = pBegin; *pCh != '\0'; pCh++) 10 { 11 s... 阅读全文
摘要:
1 int matrix[MAX][MAX]; 2 void PrintMatrix(int x,int y,int start,int n) 3 { 4 if(n==0) 5 return ; 6 if(n==1) 7 { 8 matrix[x][y] = start; 9 return ; 10 } 11 int i,j; 12 for(j=y;jy;j--) 17 mat... 阅读全文
摘要:
1 union 2 { 3 short s; 4 char c[sizeof(short)]; 5 }test; 6 7 int main() 8 { 9 //method 1 10 int a = 0x12345678; 11 if(*((char *)&a) == 0x12) 12 printf("big-endian\n"); 13 else 14 printf("l... 阅读全文
摘要:
int LCS(char *a,char *b) { if(a==NULL || b==NULL) return 0; int len_a = strlen(a); int len_b = strlen(b); int f[M][N]; for(int i=1;i f[i-1][j] ? f[i][j-1]:f[i-1][j]); } } return f[i-1][j-1]; } 阅读全文
摘要:
1 void Calculate(int a) 2 { 3 int pa = a; 4 int count = 0; 5 int b[20] = {0}; 6 7 //将pa按位存储到数组b 8 while(pa > 0) 9 { 10 b[count++] = pa%10; 11 pa = pa/10; 12 } 13 bool flag = tr... 阅读全文
摘要:
1 char *MyStrcpy(char *des,const char *src) 2 { 3 assert(des != NULL && src != NULL); 4 char *pstr = des; 5 while((*pstr++ = *src++)!= '\0'); 6 return des; 7 } 8 9 char *MyStrcat(char *des,... 阅读全文