2013年9月22日

练习1-21:编写程序entab,将空格串替换为最少数量的制表符和空格。。。(C程序设计语言 第2版)

摘要: #include #define N 5main(){ int i, j, c, lastc; lastc = 'a'; i = j = 0; while ((c=getchar()) != EOF) { if (lastc == ' ' && c == ' ') i++; else if (c == ' ') { lastc = ' '; i = 1; } else { for (j=0; j... 阅读全文
posted @ 2013-09-22 17:54 Samuel Yang 阅读(602) 评论(0) 推荐(1) 编辑
2013年9月18日

练习1-16:修改打印最长文本行的程序的主程序main,使之可以打印任意长度的输入行的长度,并尽可能多地打印文本(C程序设计语言 第2版)

摘要: 该书英文配套答案Answer to Exercise 1-16, page 30Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. /* This is the first program exercise where the spec isn't entirely * clear. The spec says, ' 阅读全文
posted @ 2013-09-18 18:51 Samuel Yang 阅读(1254) 评论(0) 推荐(0) 编辑

练习1-13:编写一个程序,打印输入中单词长度的直方图(水平)(C程序设计语言 第2版)

摘要: 简单未考虑标点符号#include #define MAX_WORD_LEN 10#define BLANK 0#define IN_WORD 1#define START 2main(){ int c, word_len, last_ch, i, j, len_array[MAX_WORD_LEN+1]; for(i=0; i MAX_WORD_LEN){ len_array[MAX_WORD_LEN]++; }else{ len_array[i-1]... 阅读全文
posted @ 2013-09-18 17:17 Samuel Yang 阅读(417) 评论(0) 推荐(0) 编辑
2013年9月17日

练习1-12:编写一个程序,以每行一个单词的形式打印其输入(C程序设计语言 第2版)

摘要: #include #define NOT_BLANK 1#define BLANK 0main(){ int c; int last_ch = NOT_BLANK; while ((c=getchar()) != EOF){ if (c == ' ' || c == '\n' || c == '\t'){ if (last_ch == NOT_BLANK) putchar('\n'); last_ch = BLANK;//这条语句可以包括在最近的if里面 }else{ ... 阅读全文
posted @ 2013-09-17 10:48 Samuel Yang 阅读(303) 评论(0) 推荐(0) 编辑
2013年9月16日

练习2-3:十六进制数字字符串转换为等价整型值,字符串允许包含的数字包括:0~9、a~f、A~F、x、X(C程序设计语言 第2版)

摘要: #include #include #include int htoi(char s[]){ unsigned int len = strlen(s); unsigned int i = 0; int sum = 0; while(len){ --len; if ('a' <= s[len] && s[len] <= 'f'){ sum += (s[len] - 'a' + 10) * pow(16, i++); }else if ('A' <= s[len] && s[len] 阅读全文
posted @ 2013-09-16 12:25 Samuel Yang 阅读(286) 评论(0) 推荐(0) 编辑

练习1-23:删去C语言程序中所有的注释语句(C程序设计语言 第2版)

摘要: 1 #include 2 main() 3 { 4 FILE * fp_i; 5 FILE * fp_o; 6 fp_i = fopen("input.txt", "r"); 7 fp_o = fopen("output.txt", "w"); 8 char ch; 9 int sign;10 while((ch=fgetc(fp_i)) != EOF){11 if (ch == '/' ){12 13 ch=fgetc(fp_i);14 if (ch == '/'){1... 阅读全文
posted @ 2013-09-16 10:46 Samuel Yang 阅读(247) 评论(0) 推荐(0) 编辑
2013年7月26日

GCC 源码编译 mpc mprf gmp 不用make(否则会有lib/libgmp.so: could not read symbols: File in wrong format等错误)

摘要: 错误信息:lib/libgmp.so: could not read symbols: File in wrong formatcollect2: error: ld returned 1 exit status该错误直接原因是对三个库进行了make安装。解压gcc 压缩包后,在contrib文件夹中有一个download_prerequisites文件,vim打开之,可以看到当前版本gcc依赖的三个库mpfr、mpc、gmp及其下载地址,以及链接三个库到gcc目录下的操作。可按其说明运行之自动下载安装,也可自己从网上下载三个库。若选择自行下载三个库则又有两种处理方法: 1、在confi... 阅读全文
posted @ 2013-07-26 15:03 Samuel Yang 阅读(1661) 评论(0) 推荐(0) 编辑
2013年7月13日

Emacs-24.1 + ECB-2.40 + cscope-15.7a + cedet 无root权限指定目录安装与配置

摘要: emacs等安装在~/INSTALL目录下,在~下新建一个INSTALL目录。1. emacs-24.1.tar.gz ecb-2.40.tar.gz cscope-15.7a.tar.bz2下载到~/Download目录下2. 依次执行: tar -zxvf emacs-24.1.tar.gz mv emacs-24.1 ../INSTALL tar -zxvf ecb-2.40.tar.gz mv ecb-2.40 ../INSTALL tar -jxvf cscope-15.7a.tar.bz2 mv cscope-15.7a ../INSTALL ecb、cscope 无... 阅读全文
posted @ 2013-07-13 16:26 Samuel Yang 阅读(601) 评论(0) 推荐(0) 编辑
2013年7月5日

Python list嵌套 三维数组

摘要: cores_multicast = [[] for i in xrange(64)]temp_list = [0, 1]temp_list2 = [0, 3]cores_multicast[0].append(temp_list)cores_multicast[0].append(temp_list2)print cores_multicastprint cores_multicast[0]print cores_multicast[0][0]print cores_multicast[0][0][0]print cores_multicast[0][0][1]>>> === 阅读全文
posted @ 2013-07-05 17:02 Samuel Yang 阅读(4648) 评论(0) 推荐(0) 编辑
2013年6月6日

Python 正则表达式 带分组的替换 \g<1> \g<2>

摘要: 1 import re 2 p = re.compile(r'^(task_cnt\s)\S*\s\S$', re.M) 3 for i in range(0, 11): 4 filename = 'graph' + str(1000 + 100 * i) + '.tgffopt' 5 fp_o = open(filename, 'r') 6 all = fp_o.read() 7 fp_o.close 8 print all 9 fp_i = open(filename, 'w')10 ... 阅读全文
posted @ 2013-06-06 21:49 Samuel Yang 阅读(3723) 评论(0) 推荐(0) 编辑