03 2015 档案
摘要:问题来自:《C程序设计》(第四版)谭浩强 清华大学出版社 第291页有n个人围城一圈,顺序排号。从第一个人开始报数(从1报到m),凡是报到m的人退出圈子,接着从循环队列的下一位开始报数(该数为1)。问最后留下的是原来几号的那位。注:本例为模拟题,按要求写程序即可。示例代码: 1 #include ...
阅读全文
摘要:交换 int a, int b: | 交换 int *p, int *q 的地址 void ( int *a, int *b) | void...
阅读全文
摘要:原理: 例如:用牛顿法求下面方程在1.5附近的根: 2*x^3 - 4*x^2 + 3*x -6 = 0故有:f(x) = 2*x^3 - 4*x^2 + 3*x - 6 df/dx = 6*x^2 - 8*x + 3 x := x - f(x)/(df/...
阅读全文
摘要:求:S = a + aa + aaa + aaaa + aaaaa + ... + aaaaaaaaaa; 最后一个为n个a,其中a 是一个数字。例如:2+22+222+2222+22222 (n = 5) 1 #include 2 3 int * sum( int buffer[], int ...
阅读全文
摘要:假设src.txt是包含各种ascii字符的文本文件。请提取src.txt文本中的数字,并保存在dst.txt文件中。数字之间用空格隔开。 1 #include 2 #include 3 #include 4 5 #define IN 0 6 #define OUT 1 7 8 /*从名为...
阅读全文
摘要:Problem set:运动员打靶10次,求打中90环的所有可能情况,要求用递归算法实现。 1 #include 2 #include 3 #include 4 5 void Compute(int score, int num, int buffer[]) 6 { 7 extern...
阅读全文
摘要:所谓幂集(Power Set), 就是原集合中所有的子集(包括全集和空集)构成的集族。例如集合S = {a,b,c};那么S的幂集P(S) = { Ø ,{a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c} }。N个元素的集合的幂集共有2^N个集合构成的元素。下面是...
阅读全文
摘要:1 struct BiTree 2 { 3 struct BiTree *lchild; 4 struct BiTree *rchild; 5 }; 6 7 int Node(struct BiTree *T) 8 { 9 if(T == NULL)10 ...
阅读全文
摘要:C语言标准库中没有 int substr(char *s1, char *s2)/*字符串匹配,成功返回所在位置,不成功返回-1*/ 函数,下面是利用已有的库函数自己实现的substr函数。代码如下: 1 #include 2 3 #include 4 5 int substr(char *...
阅读全文
摘要:1:甲乙两队进行比赛,甲队有a、b、c三人,乙队有x、y、z三人,有人想知道比赛对手,a说不和x比赛,c说不和x,z比赛,编程找三对赛手名单。 1 #include 2 3 int main() 4 { 5 char x = 'a',y,z; 6 for(x = 'a'; (x ...
阅读全文
摘要:在信息论中,两个等长字符串之间的汉明距离是两个字符串对应位置的字符不同的个数。 1 #include 2 /*给定两个字符串,求两个字符串的汉明距离*/ 3 int hamming_distance(char *s1, char *s2) 4 { 5 int i; 6 int di...
阅读全文

浙公网安备 33010602011771号