随笔分类 -  C/C++

摘要:直接上题目:为下面程序当x=9999时的运行结果? 1 int func(int i) 2 { 3 int c = 0; 4 while(x) 5 { 6 c++; 7 x = x&(x-1); 8 } 9 return c;1... 阅读全文
posted @ 2015-04-16 19:29 天天AC 阅读(209) 评论(0) 推荐(0)
摘要:Libevent 是一个用C语言编写的、轻量级的开源高性能网络库.(事件触发)官网:http://libevent.org/优点: (1)事件驱动,高性能 (2)轻量级,专注于网络 (3)跨平台,支持Windows,Linux,MacOS等 (4)支持多路I/O复用,epoll,poll,d... 阅读全文
posted @ 2015-04-14 20:02 天天AC 阅读(427) 评论(0) 推荐(0)
摘要:这里要用到C++-STL中的set容器,这个容器的特点就是去重!设计测试:给定两个集合a[] = {1,2,3,4,5,6};b[] = {4,5,6,7,8,9};则集合的交集为4,5,6代码如下,仅供参考: 1 #include 2 #include 3 #include 4 #inclu... 阅读全文
posted @ 2015-04-04 14:25 天天AC 阅读(467) 评论(0) 推荐(0)
摘要:1.首先你需要下载它,在http://www.linkdata.se/sourcecode/memwatch/2.该内存工具是开源的(我也很喜欢开源^_^...),无需安装,只要在你的代码中包含它的头文件.像这样 #include "memwatch"3.目前用到的最新版本是memwatch-2.7... 阅读全文
posted @ 2015-03-08 14:56 天天AC 阅读(1380) 评论(0) 推荐(0)
摘要:试编写一个程序寻找一条通过迷宫的路径。 一个迷宫可以看成是一个矩阵(数组),它有一个入口单元和一个出口单元,图中阴影处表示障碍物,白格表示可以通行的道路。只能从入口进去,从出口出去,中间只能通过白格子(即只能从一个白格单元走到一个相邻的白格单元,相邻指上、下、左、右四个单元),遇见死路时,退回去重... 阅读全文
posted @ 2014-12-20 20:44 天天AC 阅读(310) 评论(0) 推荐(0)
摘要:找规律填写N×N方阵。如N=8时, 其方阵为: 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 2 3 3 3 3 2 1 1 2 3 4 4... 阅读全文
posted @ 2014-12-20 20:40 天天AC 阅读(222) 评论(0) 推荐(0)
摘要:1 /** 2 快速排序的原理: 3 左边的数比middle小 4 右边的数比middle大 5 **/ 6 # include 7 # include 8 void sort(int a[],int low,int high) 9 {10 int m = a[(low+h... 阅读全文
posted @ 2014-12-17 19:21 天天AC 阅读(236) 评论(0) 推荐(0)
摘要://数组的初始化方法# include# includeint main(){ int a[3][4]; int num = 0;//方法一: /* for (int i = 0; i < 3 * 4; i++) { a[i / 4][i % 4] = n... 阅读全文
posted @ 2014-11-28 21:10 天天AC 阅读(309) 评论(0) 推荐(0)
摘要://选择排序,前提必须了解找到数组中最小数和最大数的算法# include# include# includeint main(){ //利用时间随机数生成数组 time_t ts; unsigned int data = time(&ts); srand(data); ... 阅读全文
posted @ 2014-11-27 22:20 天天AC 阅读(303) 评论(0) 推荐(0)
摘要:1.首先说一下函数的副本机制看一段简单的代码 1 # include 2 # include 3 4 int add(int n, int m) 5 { 6 int z = n + m; 7 return z; 8 } 9 10 int main()11 {12 print... 阅读全文
posted @ 2014-11-27 20:27 天天AC 阅读(574) 评论(0) 推荐(0)
摘要:直接上带代码 1 #define _CRT_SECURE_NO_WARNINGS//关闭安全检查 2 # include 3 # include 4 /* 5 伪随机数的生成 6 */ 7 int main1() 8 { 9 int seed = 0xffffffff,i;10 ... 阅读全文
posted @ 2014-11-08 09:44 天天AC 阅读(200) 评论(0) 推荐(0)
摘要:wchar_t的解释可以看这里:这里程序和解析: 1 # include 2 # include 3 # include//设置本地化 4 int main() 5 { 6 //常规的输出汉字 7 char s[100] = "我是大好人"; 8 printf("%c%c\n... 阅读全文
posted @ 2014-11-07 22:20 天天AC 阅读(1612) 评论(0) 推荐(0)
摘要:1.今天使用 _itoa函数,出现蛋疼的问题原来又是微软的一套。2.如何解决呢?在第一行添一句:#define _CRT_SECURE_NO_WARNINGS //关闭安全检查代码如下: 1 #define _CRT_SECURE_NO_WARNINGS 2 # include 3 # inc... 阅读全文
posted @ 2014-11-05 20:42 天天AC 阅读(744) 评论(0) 推荐(0)
摘要:1.通过两张图说明(1)全局变量运行成功(2)局部变量运行失败大家都知道,重复在main函数中定义变量会报错但为什么上面定义不报错呢?得出结论: (1)全局变量定义和声明有区别 (2)局部变量定义和声明没有区别说明: 例如 int a :是定义 ,而 int a = 1 是赋值!看看函数吧!成... 阅读全文
posted @ 2014-11-01 21:35 天天AC 阅读(363) 评论(0) 推荐(0)
摘要:直接上代码,内置注解1.server端 1 /** 2 server端 3 */ 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include... 阅读全文
posted @ 2014-10-29 19:37 天天AC 阅读(279) 评论(0) 推荐(0)