09 2015 档案
枚举法
摘要:/**口袋里有红、黄、蓝、白、黒5种颜色的球若干,每次从口袋中先后取出3个球,问得到3种不同颜色的球的可能取法,输出每种排列的情况**/#include #include int main(){ enum Color {red,yellow,blue,white,black}...
阅读全文
环状序列
摘要:长度为n的环状串有n种表示法,分别为从某个位置开始顺时针得到。 求字典序最小的,也就是最小表示#include #include #define maxn 105int less(char *s,int p,int q){ int i,n; n=strlen(s); f...
阅读全文
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...
阅读全文
生成元
摘要:算法竞赛入门经典第二版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...
阅读全文
蛇形填数
摘要:样例输入: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;...
阅读全文
n个灯,k个人的开灯问题
摘要:/**有n个灯,编号为1-n。第一个人把所以灯打开,第二个人按下 所有编号为2的倍数的开关,第三个人按下3的倍数的开关,依次类推, 一共有k个人,问最后有哪些灯开着? 样例输入: 7 3 样例输出: 1 5 6 7 **/#include #include #include int...
阅读全文
排序算法简介及其C实现
摘要:排序算法(Sorting Algorithm)是计算机算法的一个组成部分。排序的目标是将一组数据 (即一个序列) 重新排列,排列后的数据符合从大到小 (或者从小到大) 的次序。这是古老但依然富有挑战的问题。Donald Knuth的经典之作《计算机程序设计艺术》(The Art o...
阅读全文
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,...
阅读全文
指针部分,建立动态数组
摘要:#include #include void check(int *p[]){ int i; printf("没及格的成绩有:\n"); for(i=0;i<5;i++) { if(p[i]<60) printf("%d ...
阅读全文
将若干字符串按字母顺序(由小到大)输出(用指针)
摘要:#include #include #include void sortt(char *name[],int n){ int i,j; char *temp; for(i=0;i0) /**设这两个字符串为str1,str2,若str...
阅读全文
返回指针值的函数(2)
摘要:请自己理解,比较简单/**对前面那个问题,输出有不及格成绩的学生的所有成绩**/#include #include int main(){ float a[3][4]={{50,99,80,50},{55,60,85,90},{10,54,74,26}}; float ...
阅读全文
scanf从文件中读入,printf写入到文件
摘要:重定向方式读写文件#include #define LOCALint main(){ #ifdef LOCAL freopen("input.txt","r",stdin); //使得scanf从文件input.txt读入 //r只读,如果文件不存在,出错 ...
阅读全文
scanf从文件中读入,printf写入到文件
摘要:重定向方式读写文件#include #define LOCALint main(){ #ifdef LOCAL freopen("input.txt","r",stdin); //使得scanf从文件input.txt读入 //r只读,如果文件不存在,出错 ...
阅读全文
用指向函数的指针作函数参数
摘要:/**有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 ))...
阅读全文
使用指向函数的指针
摘要:/**输入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)...
阅读全文
用指针将字符串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)...
阅读全文
用指针将字符串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)...
阅读全文
用指针方法排序数组
摘要:#include #include //将一维数组中10个数按大到小的顺序排列输出int main(){ void sort(int x[],int n); //void sort(int *x,int n) int i,x[10]; int *p; ...
阅读全文
struct和typedef struct
摘要:“`typedef声明,简称typedef,为现有类型创建一个新的名字,或称为类型别名,在结构体定义,还有一些数组等地方都大量的用到。 比如: typedef int DataType; 给整型int起了一个新名字DataType,以后用DataType就如同int一样。 分三块来...
阅读全文
结构体类型定义的一般式
摘要:struct 结构体名{ 类型名1 域名1; 类型名2 域名2; 类型名3 域名3; 类型名4 域名4; ... ... 类型名n 域名n;};说明:结构体类型是用户自定义类型,使用时需要按照规定的形式定义类型标识符,然后才能定义相应类型...
阅读全文
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...
阅读全文
malloc函数详解
摘要:一、原型:extern void *malloc(unsigned int num_bytes); 头文件:#include 或 #include (注意:alloc.h 与 malloc.h 的内容是完全一致的。) 功能:分配长度为num_bytes字节的内存块 说明:如果分配成功...
阅读全文
浙公网安备 33010602011771号