09 2015 档案
枚举法
摘要:/**口袋里有红、黄、蓝、白、黒5种颜色的球若干,每次从口袋中先后取出3个球,问得到3种不同颜色的球的可能取法,输出每种排列的情况**/#include #include int main(){ enum Color {red,yellow,blue,white,black}... 阅读全文
posted @ 2015-09-28 20:15 cnxo 阅读(184) 评论(0) 推荐(0)
环状序列
摘要:长度为n的环状串有n种表示法,分别为从某个位置开始顺时针得到。 求字典序最小的,也就是最小表示#include #include #define maxn 105int less(char *s,int p,int q){ int i,n; n=strlen(s); f... 阅读全文
posted @ 2015-09-28 19:32 cnxo 阅读(193) 评论(0) 推荐(0)
HDOJ1002题A + B Problem II,2个大数相加
摘要:Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.Input The fir... 阅读全文
posted @ 2015-09-26 15:41 cnxo 阅读(172) 评论(0) 推荐(0)
生成元
摘要:算法竞赛入门经典第二版p52 例题3-5: 如果x+x的各个数字之和得到y,就是说x是y的生成元。给出n(1#include #define maxn 100005int anx[maxn];int main(){ int T,n; memset(anx,0,sizeo... 阅读全文
posted @ 2015-09-26 15:10 cnxo 阅读(400) 评论(0) 推荐(0)
蛇形填数
摘要:样例输入:4样例输出:10 11 12 19 16 13 28 15 14 37 6 5 4#include #include #include int main(){ int a[50][50]; int i,j,x,y,cot,n;... 阅读全文
posted @ 2015-09-22 20:44 cnxo 阅读(137) 评论(0) 推荐(0)
n个灯,k个人的开灯问题
摘要:/**有n个灯,编号为1-n。第一个人把所以灯打开,第二个人按下 所有编号为2的倍数的开关,第三个人按下3的倍数的开关,依次类推, 一共有k个人,问最后有哪些灯开着? 样例输入: 7 3 样例输出: 1 5 6 7 **/#include #include #include int... 阅读全文
posted @ 2015-09-22 19:57 cnxo 阅读(228) 评论(0) 推荐(0)
排序算法简介及其C实现
摘要:排序算法(Sorting Algorithm)是计算机算法的一个组成部分。排序的目标是将一组数据 (即一个序列) 重新排列,排列后的数据符合从大到小 (或者从小到大) 的次序。这是古老但依然富有挑战的问题。Donald Knuth的经典之作《计算机程序设计艺术》(The Art o... 阅读全文
posted @ 2015-09-18 16:42 cnxo 阅读(243) 评论(0) 推荐(0)
HDOJ 1005 Number Sequence
摘要:Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n,... 阅读全文
posted @ 2015-09-15 20:09 cnxo 阅读(90) 评论(0) 推荐(0)
指针部分,建立动态数组
摘要:#include #include void check(int *p[]){ int i; printf("没及格的成绩有:\n"); for(i=0;i<5;i++) { if(p[i]<60) printf("%d ... 阅读全文
posted @ 2015-09-14 21:47 cnxo 阅读(217) 评论(0) 推荐(0)
将若干字符串按字母顺序(由小到大)输出(用指针)
摘要:#include #include #include void sortt(char *name[],int n){ int i,j; char *temp; for(i=0;i0) /**设这两个字符串为str1,str2,若str... 阅读全文
posted @ 2015-09-14 19:59 cnxo 阅读(1945) 评论(0) 推荐(0)
返回指针值的函数(2)
摘要:请自己理解,比较简单/**对前面那个问题,输出有不及格成绩的学生的所有成绩**/#include #include int main(){ float a[3][4]={{50,99,80,50},{55,60,85,90},{10,54,74,26}}; float ... 阅读全文
posted @ 2015-09-12 17:00 cnxo 阅读(127) 评论(0) 推荐(0)
scanf从文件中读入,printf写入到文件
摘要:重定向方式读写文件#include #define LOCALint main(){ #ifdef LOCAL freopen("input.txt","r",stdin); //使得scanf从文件input.txt读入 //r只读,如果文件不存在,出错 ... 阅读全文
posted @ 2015-09-10 21:22 cnxo 阅读(182) 评论(0) 推荐(0)
scanf从文件中读入,printf写入到文件
摘要:重定向方式读写文件#include #define LOCALint main(){ #ifdef LOCAL freopen("input.txt","r",stdin); //使得scanf从文件input.txt读入 //r只读,如果文件不存在,出错 ... 阅读全文
posted @ 2015-09-10 21:22 cnxo 阅读(516) 评论(0) 推荐(0)
用指向函数的指针作函数参数
摘要:/**有2个整数a,b,有用户输入1,2,或3,如输入1,程序就给出a和b中大者,输入2,就给出a和b中小者,输入3,就给出a和b的和**/#include #include int main(){ int f(int x,int y,int (*p)(int ,int ))... 阅读全文
posted @ 2015-09-10 15:04 cnxo 阅读(212) 评论(0) 推荐(0)
使用指向函数的指针
摘要:/**输入2个整数,然后让用户选择1或2,选1时调用max函数,输出2者中的大数,选2时调用min函数,输出2者中的小数**/#include #include int main(){ int max(int x,int y); int min(int x,int y)... 阅读全文
posted @ 2015-09-10 14:34 cnxo 阅读(190) 评论(0) 推荐(0)
诗词—《吾念谁悲》
摘要:《吾念谁悲》 深夜半瓶酒, 天涯何处有. 莫问她人在, 莫痴吾念谁. 谁人为汝醉, 谁人为汝悲. ... 阅读全文
posted @ 2015-09-10 13:58 cnxo 阅读(151) 评论(0) 推荐(0)
用指针将字符串a的内容复制到字符串b
摘要:#include #include /**int main(){ char a[]="i love you very mach!",b[100]; int i; for(i=0;*(a+i)!='\0';i++) { *(b+i)=*(a+i)... 阅读全文
posted @ 2015-09-09 21:50 cnxo 阅读(274) 评论(0) 推荐(0)
用指针将字符串a的内容复制到字符串b
摘要:#include #include /**int main(){ char a[]="i love you very mach!",b[100]; int i; for(i=0;*(a+i)!='\0';i++) { *(b+i)=*(a+i)... 阅读全文
posted @ 2015-09-09 21:50 cnxo 阅读(863) 评论(0) 推荐(0)
用指针方法排序数组
摘要:#include #include //将一维数组中10个数按大到小的顺序排列输出int main(){ void sort(int x[],int n); //void sort(int *x,int n) int i,x[10]; int *p; ... 阅读全文
posted @ 2015-09-09 18:26 cnxo 阅读(1316) 评论(0) 推荐(0)
struct和typedef struct
摘要:“`typedef声明,简称typedef,为现有类型创建一个新的名字,或称为类型别名,在结构体定义,还有一些数组等地方都大量的用到。 比如: typedef int DataType; 给整型int起了一个新名字DataType,以后用DataType就如同int一样。 分三块来... 阅读全文
posted @ 2015-09-08 20:07 cnxo 阅读(162) 评论(0) 推荐(0)
结构体类型定义的一般式
摘要:struct 结构体名{ 类型名1 域名1; 类型名2 域名2; 类型名3 域名3; 类型名4 域名4; ... ... 类型名n 域名n;};说明:结构体类型是用户自定义类型,使用时需要按照规定的形式定义类型标识符,然后才能定义相应类型... 阅读全文
posted @ 2015-09-08 19:53 cnxo 阅读(305) 评论(0) 推荐(0)
HDOJ1020 Encoding
摘要:Problem Description Given a string containing only ‘A’ - ‘Z’, we could encode it using the following method: Each sub-string containing k sam... 阅读全文
posted @ 2015-09-07 16:06 cnxo 阅读(134) 评论(0) 推荐(0)
malloc函数详解
摘要:一、原型:extern void *malloc(unsigned int num_bytes); 头文件:#include 或 #include (注意:alloc.h 与 malloc.h 的内容是完全一致的。) 功能:分配长度为num_bytes字节的内存块 说明:如果分配成功... 阅读全文
posted @ 2015-09-07 10:58 cnxo 阅读(278) 评论(0) 推荐(0)