摘要: 原型:extern void *memcpy(void *dest, void *src, unsigned int count); 用法:#include <string.h> 功能:由src所指内存区域复制count个字节到dest所指内存区域。 说明:src和dest所指内存区域不能重叠,函数返回指向dest的指针。 举例: // memcpy.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char d[20]; cl 阅读全文
posted @ 2011-06-23 15:34 為愛西行 阅读(140) 评论(0) 推荐(0)
摘要: 原型:extern char *strstr(char *haystack, char *needle); 用法:#include <string.h> 功能:从字符串haystack中寻找needle第一次出现的位置(不比较结束符NULL)。 说明:返回指向第一次出现needle位置的指针,如果没找到则返回NULL。 举例: // strstr.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char *l="lo 阅读全文
posted @ 2011-06-23 15:30 為愛西行 阅读(124) 评论(0) 推荐(0)
摘要: 求组合数:求n个数(1....n)中k个数的组合....如:combination(5,3)要求输出:543,542,541,532,531,521,432,431,421,321#include <stdio.h>int pop(int *);int push(int );void combination(int, int );int stack[3] = {0};int top = -1;int main(){ int m, n; printf("Input two numbers:\n"); while( 2!=scanf("%d%*c%d&qu 阅读全文
posted @ 2011-06-23 13:51 為愛西行 阅读(256) 评论(0) 推荐(0)
摘要: 有一个数组a[1000]存放0--1000;要求每隔二个数删掉一个数,到末尾时循环至开头继续进行,求最后一个被删掉的数的原始下标位置。以7个数为例:{0,1,2,3,4,5,6,7}0-->1-->2(删除)-->3-->4-->5(删除)-->6-->7-->0(删除),如此循环直到最后一个数被删除。#include <stdio.h>#define MAX 3int main(){ int arr[MAX]; for(int i=0; i<MAX; ++i) //数组初始化 arr[i]=i; int count=0; in 阅读全文
posted @ 2011-06-23 09:56 為愛西行 阅读(135) 评论(0) 推荐(0)
摘要: 1 /* 2 题目如下: 3 有1,2,....一直到n的无序数组,求排序算法,要求时间复杂度为O(n), 空间复杂度为O(1)。使用交换,而且一次只能交换两个数。 4 解题思路: 5 因为从1,2......n刚好需要一个数组a[n],排序后,a[i]=i+i; 所以就出現了,a[a[i]-1] = a[i]; 最终完成以后,i的位置上放值得数据值会是i+1问题的关键在于数组的值是1到n,否则是不可能在时间复杂度为O(n),空间复杂度为O(1)内完成的 6 */ 7 8 #include <iostream.h> 9 #include <assert.h>10 #in 阅读全文
posted @ 2011-06-20 15:13 為愛西行 阅读(384) 评论(0) 推荐(1)
摘要: Bjarne在他的The C++ Programming Language裏面給出過一個助記的方法:把一個聲明從右向左讀。1 char *const cp; //cp is a const pointer to char2 3 const char *p; //p is a pointer to const char4 5 char const *p; //因為C++裏面沒有const *的運算符,所以const只能屬於前面的類型 阅读全文
posted @ 2011-06-20 14:41 為愛西行 阅读(116) 评论(0) 推荐(0)
摘要: 1 #include <stdio.h> 2 #include <string.h> 3 int main() 4 { 5 char str[100]; 6 printf("input a string:\n"); 7 gets(str); 8 9 int i = 0;10 int j;11 while(i <= strlen(str)-1)12 {13 j = i+1;14 printf("delete result %d\n", strlen(str));15 while(j <= strlen(str)-1)16 阅读全文
posted @ 2011-06-20 14:01 為愛西行 阅读(260) 评论(0) 推荐(1)
摘要: 原型:extern char *strcat(char *dest,char *src);用法:#include <string.h>功能:把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'。说明:src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。返回指向dest的指针。举例: 1 // strcat.c 2 3 #include <syslib.h> 4 #include <string.h> 5 6 main() 7 { 8 char d[20]=&qu 阅读全文
posted @ 2011-06-20 13:37 為愛西行 阅读(210) 评论(0) 推荐(1)
摘要: 1、scanf()不能輸入空格,即把空格當'\0'來看;2、printf()和puts()沒什麼區別; 阅读全文
posted @ 2011-06-20 13:19 為愛西行 阅读(138) 评论(0) 推荐(0)
摘要: 1、strlen()不包括結尾的'\0',sizeof()包括字符串結尾的‘\0’,因此長度大1; 阅读全文
posted @ 2011-06-20 13:06 為愛西行 阅读(110) 评论(0) 推荐(0)