上一页 1 ··· 56 57 58 59 60 61 62 63 64 ··· 69 下一页
摘要: c++引入友元的原因在某些情况下,允许特定的非成员函数访问类的私有成员。在类中以关键字friend开始(只能出现在类定义的内部),声明为友元的可以为类、类的成员函数、普通的非成员函数。速览#include #include using namespace std;class b;class f { friend b; public: void print_a() { cout #include using namespace std;class Sales_item;class A { public: void fuc(Sales_item &)... 阅读全文
posted @ 2013-08-06 19:49 jihite 阅读(373) 评论(0) 推荐(0)
摘要: StackExchange.com上有两个贴子(贴子一,贴子二),贴子名叫“Whatisthesinglemosteffectivethingyoudidtoimproveyourprogrammingskills?”(对你的编程技术提高最有效的一件事是什么?)回复的人中给了很多很不错的建议,我把他们总结了一下,十条,相信一定会对你有用。和比自己聪明的能力比自己强的人工作。学习他们的代码,他们的做事方法,看一看那些人是怎么处理错误的。总是倾听别人怎么说,无论那个的资历和职位是什么样的。实践,实践,实践,总是不满意于一开始出来的事。多问问自己,现在在写什么代码?为什么要这样写成这样?还有没有更好 阅读全文
posted @ 2013-08-06 19:16 jihite 阅读(632) 评论(0) 推荐(0)
摘要: 缘起#include #include using namespace std;int main(){ istringstream iss; string str1, str2, str3, str4, str5, str6; iss.str("I love you"); iss >> str1 >> str2 >> str3; cout > str4 >> str5 >> str6; cout #include using namespace std;int main(){ istringstream is 阅读全文
posted @ 2013-08-06 16:18 jihite 阅读(543) 评论(0) 推荐(0)
摘要: 为了使自己的程序有很好的移植性,c++程序员应该尽量使用size_t和size_type而不是int, unsigned1. size_t是全局定义的类型;size_type是STL类中定义的类型属性,用以保存任意string和vector类对象的长度2. string::size_type制类型一般就是unsignedint,但是不同机器环境长度可能不同win32和win64上长度差别;size_type一般也是unsignedint 3. 使用的时候可以参考: string::size_typea=123; vectorsize_typeb=234; size_tb=456; 4. s.. 阅读全文
posted @ 2013-08-05 23:02 jihite 阅读(28736) 评论(1) 推荐(9)
摘要: 问题描述一堆数(例如6, 2, 2, 6, 3, 4, 6, 6, 6, 6),总共10个,其中”6“的个数超过总数的一半5,找出这个个数超过过半的那个数。思路从头到尾遍历,两个数相同接着往后遍历;否则删掉这两个数,接着往后遍历。因为所找的那个数过半,所以不同的数相抵,抵消掉最后还会至少剩下一个那个要找的数。图示代码#include using namespace std;typedef struct node{ int num; node *before; node *next;}node;int main(){ node *p_now, *p_next; no... 阅读全文
posted @ 2013-07-17 22:39 jihite 阅读(1419) 评论(0) 推荐(0)
摘要: 出自c++ primer(4th)282页,26题题意数组ia[]={0,1,1,2,3,5,8,13,21,55,89};把ia复制到一个list容器中。使用单个迭代器参数版本的erase()函数将list容器中的奇数元素值删掉。代码#include #include using namespace std;int main(){ int ia[] = {0,1,1,2,3,5,8,13,21,55,89}; list ilist(ia, ia+11); list::iterator beg = ilist.begin(); for(;beg!=ilist.end()... 阅读全文
posted @ 2013-07-07 09:39 jihite 阅读(517) 评论(0) 推荐(0)
摘要: 问题描述5, 5,-7, 5, 9, -1, 5, 1, 9, 4, 6 这堆数中两个数的和为10的组合有:5+5, 9+1, 4+6,如何快速的找出这样的组合?假定数组a[]存放元素,数组大小为len_a指定和为aim思路一先排序,low=0(最低位置),up=len_a(最高位置)当a[low]+a[up]>aim时,hig=high-1当a[low]+a[up] #include using namespace std; void printPairSums(int data[], int size, int sum); int main(int argc, char* a... 阅读全文
posted @ 2013-07-04 17:16 jihite 阅读(1384) 评论(0) 推荐(0)
摘要: 在32位系统中,存储一位整型(int)数需要4个字节(4B),如果开辟一个空间,把其中的某个位1,就从原来的32b减少到1b,大大节省了空间。原理字符数组entry是存储位的数组,我们把数字N存到entry中,则把第N位置1:entry[nBits/8] = entry[nBits/8] | (1 << (nBits%8) )检验第N位是否为1:entry[nBits/8] & (1 << (nBits%8)图示函数void setBit(char entry[], int nBits){ entry[nBits/8] = entry[nBits/8] | (1 阅读全文
posted @ 2013-07-03 15:20 jihite 阅读(1398) 评论(0) 推荐(0)
摘要: 问题假设:一个反应器中有两类粒子α和β,设每秒钟一个α粒子分裂成3个β粒子,而每秒钟一个β粒子分裂成一个α粒子和两个β粒子。假如在t=0时:反应器中有一个α粒子,求t秒时反应器中α粒子和β粒子的数目。根据关系列出递归关系a(t) = b(t-1)b(t) = 3*a(t-1) + 2*b(t-1)参考程序#include #include #define A_size 5 int aa(int size) //aa(t)表示t时刻α的个数{ if (size == 0) return 1; else return bb(size-1);}int bb... 阅读全文
posted @ 2013-06-25 22:59 jihite 阅读(5504) 评论(0) 推荐(2)
摘要: 1.KMP算法2.(lhy)怎么切分最省 阅读全文
posted @ 2013-06-22 20:55 jihite 阅读(306) 评论(0) 推荐(0)
上一页 1 ··· 56 57 58 59 60 61 62 63 64 ··· 69 下一页