02 2016 档案
摘要:统计单词出现的频率 参考 《C程序设计语言》第6章 结构 #include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #define MAXWORD 100 #define BUFSIZE 100 cha
阅读全文
摘要:二分查找 简易版 参考 K&R C #include <stdio.h> //binsearch函数: 在v[0..n-1]中查找x,其中v[i]<=v[i+1] //若找到返回下标(0-base),若找不到返回-1; int binsearch(int v[], int x, int low,in
阅读全文
摘要:将数字n转换为字符串并保存到s中 参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各字符的位置 void reverse(char s[]){ int c,i,j; for(i=0,j=strlen(s)-1
阅读全文
摘要:倒置字符串s中各字符的位置 其中reverse函数可以写成更紧凑的形式 void reverse(char s[]){ int c,i,j; for(i=0,j=strlen(s)-1;i<j;i++,j--){ c=s[i], s[i]=s[j], s[j]=c; } } 程序 #include
阅读全文
摘要:希尔排序 不知道怎么证明希尔排序的正确性 #include<stdio.h> void view(int Av[]); void shellsort(int v[], int n){ int gap, i, j, temp; for(gap=n/2;gap>0;gap/=2){ for(i=gap;
阅读全文
摘要:参考《C程序设计语言》 注意输出中光标的位置 对于getline, 由于函数的默认返回值类型为int, 因此这里的int可以省略。 #include<stdio.h> #define MAXLINE 4 //允许的输入行的最大长度 //getline函数: 将一行读入到s中并返回其长度 int ge
阅读全文
摘要:统计输入的行数,单词数和字符数 #include<stdio.h> #define IN 1 /*在单词内*/ #define OUT 0 /*在单词外*/ //统计输入的行数,单词数和字符数 int main(){ int c, nl, nw, nc, state; nw=nl=nc=0; sta
阅读全文
摘要:回退符\b #include <stdio.h> int main(){ printf("hello\b"); getchar(); getchar(); return 0; } 实验结果
阅读全文
摘要:堆排序 参考《算法导论》《C程序设计语言》 #include<stdio.h> int HEAPSIZE=8; int LENGTH=8; void view(int A[]); int parent(int i){//节点i的父节点下标 return (i+1)/2-1; } int left(i
阅读全文
摘要:QuickSort 参考《算法导论》,《C程序设计语言》 #include<stdio.h> void swap(int v[], int i, int j); void view(int v[]); //主元为A[r] //partition后,A[p..i]<=A[r] //A[i+1]=A[r
阅读全文
摘要:#include<stdio.h> //printd函数: 打印十进制数n void printd(int n){ if(n<0){ putchar('-'); n=-n; } if(n/10) printd(n/10); putchar(n%10+'0'); } int main() { int
阅读全文
摘要:C语言带参数的main函数 #include<stdio.h> int main(int argc,char*argv[]) { int i; for(i=0;i<argc;i++) printf("%s\n",argv[i]); getchar(); getchar(); return 0; }
阅读全文
摘要:public class Fibonacci{ public static long F(long n){ System.out.println("call F" + n); if (n == 0) return 0; if (n == 1) return 1; long t = F(n-1) +
阅读全文
摘要:格雷码 the n-1 bit code, with 0 prepended to each word, followd by the n-1 bit code in reverse order, with 1 prepended to each word. public class GrayCod
阅读全文
摘要:#include<stdio.h> void towers(int,char,char,char); int main() { int num; printf("Enter the number of disks : "); scanf("%d", &num); printf("The sequen
阅读全文
摘要:求两个数 p 和 q 的最大公约数(greatest common divisor,gcd),利用性质 如果 p > q, p 和 q 的最大公约数 = q 和 (p % q)的最大公约数。 证明:见 http://blog.csdn.net/niushuai666/article/details/
阅读全文
摘要:http://paste.ubuntu.com
阅读全文
摘要:输出第N个素数 public class FindNthPrime { public static void main(String[] args){ int N = Integer.parseInt(args[0]); //要求输出第 N 个素数 int[] PrimesVector = new
阅读全文
摘要:输出不大于N的素数的个数 Sieve of Eratosthenes 方法 素数的性质: 非素数可以分解为素数乘积。 证明 (1)n = 2 成立,n = 3 成立; (2)若 n = k 时成立,n = k+1时,假设 n = k+1 = k1*k2, 如果 k+1 是素数,k1 = 1, k2
阅读全文
摘要:今天是20号呀,大喜过望,新的一学期,开工了。 腾讯面试题:50个阶梯,你一次可以上一阶或两阶,走上去,共有多少种走法。 f(n)=f(n-1)+f(n-2) f(n)定义:上n个阶梯,有f(n)种走法 要到 第 n 个阶梯,要么经过第 n-1 个阶梯,要么不经过 斐波那契数,大数溢出问题没考虑。
阅读全文
摘要:素数 A prime is an integer greater than one whose only positive divisors are one and itself.整数的素因子分解是乘积等于此素数的集合。例如:3757208 = 2*2*2*7*13*13*397 public cl
阅读全文
摘要:赌徒赢得机会有多大? public class Gambler { public static void main(String[] args) { // Run T experiments that start with $stake and terminate on $0 and $goal i
阅读全文
摘要:public class Binary { public static void main(String[] args) { // Print binary representation of N. int N = Integer.parseInt(args[0]); int v = 1; whil
阅读全文

浙公网安备 33010602011771号