摘要:可以用strlen函数,这里我们自己写一个。注意:不能用scanf,scanf一遇到空格就认为输入结束。应该用gets(),遇到换行符或EOF结束。说明可以接受空格。#includeint main(){ char s[20]; char *p; printf("please input a string(less than 20 character):\n"); //scanf("%s",s);不能读入空格 gets(s); p = s; while(*p!='\0') p++; printf("The string lent 阅读全文
常用的算法:求闰年,判断素数,分解质因数,完数,水仙花数等
2013-08-02 11:46 by youxin, 1343 阅读, 0 推荐, 收藏,
摘要:1.如何计算闰年(Leap Year)? 四年一闰,百年不闰;四百年再闰。 具体参照:http://baike.baidu.com/view/3085625.htmJava代码booleanisLeapYear(intyear){return(year%4==0&&year%100!=0)||(year%400==0);}2.如何判断一个数是否是质数(Prime Number)? 质数又称素数。指在一个大于1的自然数中,除了1和此整数自身外,没法被其他自然数整除的数。 具体参照:http://baike.baidu.com/view/1767.htmJava代码booleani 阅读全文
算术基本定理
2013-08-02 11:31 by youxin, 1915 阅读, 0 推荐, 收藏,
摘要:内容:任何一个大于1的自然数N,都可以唯一分解成有限个质数的乘积 N=(P_1^a1)*(P_2^a2)......(P_n^an) , 这里P_1<P_2<...<P_n是质数,其诸方幂ai 是正整数。这样的分解称为N 的标准分解式。算术基本定理,又称为正整数的唯一分解定理,即:每个大于1的自然数均可写为质数的积,而且这些素因子按大小排列之后,写法仅有一种方式。例如:,。算术基本定理的内容由两部分构成:分解的存在性:分解的唯一性,即若不考虑排列的顺序,正整数分解为素数乘积的方式是唯一的。算术基本定理是初等数论中一个基本的定理,也是许多其他定理的逻辑支撑点和出发点。证明:算术 阅读全文
first-,second- and third-class value
2013-08-02 09:40 by youxin, 461 阅读, 0 推荐, 收藏,
摘要:Incomputer science, aprogramming languageis said to havefirst-class functionsif it treatsfunctionsasfirst-class citizens. Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variabl 阅读全文
转:一道笔试题-将int型数组强制转换为char*,再求strlen,涉及大小端
2013-08-02 01:34 by youxin, 462 阅读, 0 推荐, 收藏,
摘要:写出如下程序运行结果:#include#includeintmain(){inta[2000];char*p=(char*)a;for(inti=0;i int check() { union check { int i; char ch;... 阅读全文
转:git windows中文 乱码问题解决汇总
2013-07-31 15:47 by youxin, 4702 阅读, 0 推荐, 收藏,
摘要:it的Windows版本Msysgit对中文的支持不够好 。当使用时,会出现以下三种情况的中文乱码:下面的几个文件都在git安装目录下文件夹etc内。1.ls不能显示中文目录解决办法:在git/git-completion.bash中增加一行:alias ls='ls --show-control-chars --color=auto'2.git commit不能提交中文注释(错误类似:D:\versionControlGit\gitLearn>git commit -m "第一次提交README"Warning: commit message doe 阅读全文
git教程1
2013-07-31 12:11 by youxin, 440 阅读, 0 推荐, 收藏,
摘要:主要参考:官方书籍:Pro Git 中文版:http://git.perlchina.org/book/zh英文版:http://git.perlchina.org/bookhttp://git-scm.com 因一些原因无法访问,perlchina 社区制作了这个网站的实时镜像。http://git.perlchina.org 还有一个比较好的站点:http://gitref.cyj.me/zh/http://www.worldhello.net/gotgithub/Git Community Book 中文版http://gitbook.liuhui998.com/可视化学习;http:/ 阅读全文
刘汝佳黑书 pku等oj题目
2013-07-31 10:57 by youxin, 659 阅读, 0 推荐, 收藏,
摘要:原文地址:刘汝佳黑书pku等oj题目[转]作者:小博博Mr一.动态规划参考资料:刘汝佳《算法艺术与信息学竞赛》《算法导论》推荐题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1141简单http://acm.pku.edu.cn/JudgeOnline/problem?id=2288中等,经典TSP问题http://acm.pku.edu.cn/JudgeOnline/problem?id=2411中等,状态压缩DPhttp://acm.pku.edu.cn/JudgeOnline/problem?id=1112中等http://acm.pku. 阅读全文
C/C++ qsort()快速排序用法
2013-07-31 00:57 by youxin, 1724 阅读, 0 推荐, 收藏,
摘要:void qsort (void* base, size_t num, size_t size, int (*compar)(const void*,const void*));头文件stdlib.hbase Pointer to the first object of the array to be sorted, converted to a void*.num Number of elements in the array pointed by base. size_t is an unsigned integral type.size Size in by... 阅读全文
char s[]字串和char *s字串有什麼区别?
2013-07-31 00:16 by youxin, 488 阅读, 0 推荐, 收藏,
摘要:C語言有兩種字串宣告方式char s[]和char *s,兩者有什麼差異呢?Introductionchars[]="HelloWorld"; (只是用字符串常量初始化)char*s="HelloWorld";皆宣告了s字串,在C-style string的函數皆可使用,但兩者背後意義卻不相同。chars[]="HelloWorld";的s是個char array,含12個byte(包含結尾\0),"Hello World"對s來說是initializer,將字元一個一個地copy進s陣列。char*s=" 阅读全文
浙公网安备 33010602011771号