摘要: 1函数名称: calloc 函数原型: void * calloc(unsigned n,unsigned size); 函数功能: 分配n个数据项的内存连续空间,每个数据项的大小为size 函数返回: 分配内存单元的起始地址,如果不成功,返回0 2函数名称: free 函数原型: void free(void* p); 函数功能: 释放p所指的内存区 函数返回: 参数说明: p-被释放的指针 3函数名称: malloc 函数原型: void * malloc(unsigned size); 函数功能: 分配size字节的存储区 函数返回: 所分配的内存区地址,如果内存... 阅读全文
posted @ 2012-02-12 14:28 _雨 阅读(405) 评论(2) 推荐(0) 编辑
摘要: 函数名: strcat 功 能: 字符串拼接函数 用 法: char *strcat(char *destin, char *source); 程序例:#include <string.h> #include <stdio.h>int main(void) { char destination[25]; char *blank = " ", *c = "C++", *Borland = "Borland"; strcpy(destination, Borland); strcat(destination, bl 阅读全文
posted @ 2012-02-12 09:16 _雨 阅读(404) 评论(0) 推荐(0) 编辑
摘要: n圆括号和方括号,其嵌套的顺序随意。如([]())或[([ ][ ])]等为正确的匹配;而[( ])或([ ]( )或 ( ( ) ) )均为错误的匹配。 这里只介绍了()【】其实加上{}是一样的性质 看代码 1 #include<stdio.h> 2 #include<string.h> 3 int sw(char str) 4 { 5 if(str == '(') 6 return 1; 7 else 8 if(str == ')') 9 return 9;10 else11 if(str == '['... 阅读全文
posted @ 2012-02-11 19:12 _雨 阅读(333) 评论(0) 推荐(0) 编辑
摘要: 后缀式求值的方法参见我的另一篇文章 把运算符变成表达式 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int top = 0,i,k,s,num[50]; 6 char str; 7 while(scanf("%c", &str),str!='#') 8 { 9 if(str>='0'&&str<='9')10 num[++top] = str-48;11 else12 {13 switch(s 阅读全文
posted @ 2012-02-11 19:09 _雨 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int n,m,num[10000],x,y,z,d,f = 1,i,r = 0; 6 char str[10]; 7 scanf("%d", &m); 8 for(i = 1 ; i <= m;i++) 9 scanf("%d", &num[i]);10 scanf("%d",&n);11 r = m;12 while(n--)13 {14 scanf(&quo 阅读全文
posted @ 2012-02-11 19:08 _雨 阅读(344) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 int main() 3 { 4 int n,m,i,r,top = 0; 5 char stack[100]; 6 scanf("%d%d", &n,&m); 7 while(n) 8 { 9 top++;10 stack[top] = n%m;11 n = n/m;12 }13 while(top!=0)14 {15 printf("%d", stack[top]);16 top--;17 }1... 阅读全文
posted @ 2012-02-11 19:07 _雨 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 1 /* 将中缀表达式(a+b)转换为后缀表达式(ab+)的算法思想: 2 ·当读到数字直接送至输出队列中 3 ·当读到运算符t时, 4 a.将栈中所有优先级高于或等于t的运算符弹出,送到输出队列中; 5 b.t进栈 6 ·读到左括号时总是将它压入栈中 7 ·读到右括号时,将靠近栈顶的第一个左括号上面的运算符全部依次弹出,送至输出队列后,再丢弃左括号。 8 9 运用后缀表达式进行计算的具体做法: 10 ·建立一个栈S 11 ·从左到右读后缀表达式,读到数字就将... 阅读全文
posted @ 2012-02-11 14:21 _雨 阅读(799) 评论(4) 推荐(0) 编辑
摘要: 1 #include<iostream.h> 2 #include<malloc.h> 3 struct node 4 { 5 int data; 6 struct node *next; 7 }; 8 void traverse_list(struct node *head) 9 {10 int i = 1;11 struct node *p;12 p = head->next;13 while(p)14 {15 if(i != 1)16 cout<<' ';17 cou... 阅读全文
posted @ 2012-02-10 17:05 _雨 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 题目描述n个人想玩残酷的死亡游戏,游戏规则如下: n个人进行编号,分别从1到n,排成一个圈,顺时针从1开始数到m,数到m的人被杀,剩下的人继续游戏,活到最后的一个人是胜利者。请输出最后一个人的编号。输入输入n和m值。输出输出胜利者的编号。示例输入5 3示例输出4提示第一轮:3被杀第二轮:1被杀第三轮:5被杀第四轮:2被杀 1 #include<iostream.h> 2 #include<malloc.h> 3 struct mon 4 { 5 int num; 6 struct mon *next; 7 }; 8 struct mon *creat(int n) 9 阅读全文
posted @ 2012-02-10 17:05 _雨 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<malloc.h> 3 struct stu 4 { 5 int data ; 6 struct stu *next ; 7 }; 8 struct stu *creat(int n) 9 {10 int i;11 struct stu *head,*p;12 head = (struct stu *)malloc(sizeof(struct stu));13 head->next = NULL;14 for(i = 1 ; i <= n ;i++)15 {16 ... 阅读全文
posted @ 2012-02-10 17:04 _雨 阅读(480) 评论(0) 推荐(0) 编辑