- 博客(44)
- 收藏
- 关注
原创 位操作
检测一个无符号数是不为2^n-1(^为幂): x&(x+1) 将最右侧0位改为1位: x | (x+1) 二进制补码运算公式: -x = ~x + 1 = ~(x-1) ~x = -x-1 -(~x) = x+1 ~(-x) = x-1 x+y = x
2009-06-05 14:25:00
880
原创 boost
1.在boost官方网站下载最新的boost版本,我下载的是boost-jam-3.1.17-1-ntx86.zip和 boost_1_39_0.zip将他们解压,放在C盘目录下。2.将boost-jam-3.1.17-1-ntx86中的bjam.exe可执行文件copy到boost_1_39_0下 用命令模式下,在boost_1_39_0目录下,执行bjam install
2009-06-01 10:31:00
642
原创 虚函数与动态绑定
#include using namespace std;class A{public: A(){ cout f();//构造函数中对虚函数的调用采用静态绑定!(反证法!) } ~A(){ cout } virtual void f(){ cout } void g(){ cout };};class B: public A{public: B(){ co
2009-05-22 20:06:00
597
原创 very_long_int
#include #include #include #include using namespace std;class very_long_int{ friend istream& operator>>(istream& instream,very_long_int& very_long); friend ostream& operatorpublic: very_long_int o
2009-05-17 09:45:00
1582
原创 大数相加
#include #include #include #include using namespace std;class very_long_int{ friend istream& operator>>(istream& instream,very_long_int& very_long); friend ostream& operatorpublic: very_long_int()
2009-05-15 17:00:00
429
原创 copy_back使用
#include #include #include using namespace std;template struct display{ void operator()(const T& x){ cout }};int main(){ { int a[] = {0,1,2,3,4,5,6,7,8}; copy_backward(a+2,a+7,a+9);//输出区间的终点
2009-05-14 09:54:00
959
原创 copy函数的使用
#include #include #include using namespace std;template struct display{ void operator()(const T& x){ cout }};int main(){ { int a[] = {0,1,2,3,4,5,6,7,8}; copy(a+2,a+7,a);//输出区间的终点与输入区间位置重叠 fo
2009-05-14 08:41:00
1548
原创 基本算法
#include #include #include #include #include #include using namespace std;template struct display{ void operator()(const T& x){ cout }};int main(){ int a[9] = {0,1,2,3,4,5,6,7,8}; vector v1(a,
2009-05-13 21:17:00
401
原创 数值算法
#include #include #include #include #include using namespace std; int add(int a,int b);int cube( int a , int b );int square(int a,int b);int main() { int a[] = { 1,2,3,4,5 }; vector v(
2009-05-13 17:36:00
394
原创 管理学定律(转)
一、 素养 蓝斯登原则:在你往上爬的时候,一定要保持梯子的整洁,否则你下来时可能会滑倒。 提出者:美国管理学家蓝斯登。 点评:进退有度,才不至进退维谷;宠辱皆忘,方可以宠辱不惊。 卢维斯定理 :谦虚不是把自己想得很糟,而是完全不想自己。 提出者:美国心理学家卢维斯 点评:如果把自己想得太好,就很容易将别人想得很糟。 托利得定理: 测验一个人的智力是否属
2009-05-13 09:40:00
370
原创 Word Reverse
#include #include #include using namespace std;int main(){ string s,ss; getline(cin,s); getline(cin,s); int F = 1; while (getline(cin,s)) { if (s.find( ) == 4294967295&&F!=1) { getline(cin,s
2009-05-06 08:12:00
604
原创 Reverse Text
#include #include #include #include #include using namespace std;int main(int argc,int **argv){ ifstream cin("j.txt"); string s; int n =0; while(getline(cin,s)){ if(n == 0) n =1; else { r
2009-05-05 20:10:00
349
原创 Box of Brick
#include #include #include #include using namespace std;int main(){ ifstream cin("i.txt"); vector v; int e,n,m,Count = 0; int Sum,Avg; while(cin>>n){ if(n == 0)break; Count++; Sum = 0; e = 0;
2009-05-05 18:13:00
418
原创 The senven Percent Solution
#include #include #include using namespace std;int main(){ ifstream cin("ggg.txt"); string s; char ss[80]; while(cin.getline(ss,80)) { if(ss[0] ==#) break; s = ss; for (string::size_type i =0;i
2009-05-05 15:25:00
623
原创 Digital Root
#include #include #include using namespace std;int main(){ ifstream cin("h.txt"); string s; int sum; while(cin>>s){ if(s == "0")break; sum = 0; for (string::size_type i =0;i { if(s[i] == 1
2009-05-05 15:23:00
571
原创 Abbreviation
#include #include #include using namespace std;int main(){ ifstream cin("f.txt"); int n,t1,t2; cin>>n; string s,abbreviation1,abbreviation2; for (int i =0 ;i { cin>>t1; for (int j = 0;j { cin>
2009-05-05 08:57:00
716
原创 Encoding
#include #include #include using namespace std;int main(){ ifstream cin("d.txt"); string s,t; int n; cin>>n; for (int i =0;i { cin>>s; t=s[0];//t即为不同的字符,虽然是字符串但只有一个字符 int temp = 0;//用于记录待比较的字符的个
2009-05-05 08:33:00
305
原创 LOOK AND SAY
#include #include #include using namespace std;int main(){ ifstream cin("e.txt"); string s,t; int n; cin>>n; for (int i =0;i { cin>>s; t=s[0];//t即为不同的字符,虽然是字符串但只有一个字符 int temp = 0;//用于记录待比较的字符的个
2009-05-05 08:31:00
532
原创 IBM Minus One
#include #include #include using namespace std;int main(int argc,int **argv){ ifstream cin("b.txt"); int n ; cin>>n; string s; for (int i =0;i { cin>>s; cout for (string::iterator it = s.begin
2009-05-04 14:04:00
388
原创 Quicksum
#include #include #include using namespace std; int main(){ char ch[256]; int sum = 0; ifstream cin("a.txt"); while(cin.getline(ch,256)) { if(ch[0] ==#) break; for (int i = 0; ch[i] !=
2009-05-04 13:26:00
365
原创 list基本操作
#include #include #include using namespace std;int main(int argc,int **argv){ list l; l.push_back(2); l.push_back(1); l.push_back(5); l.push_front(8); l.push_back(1);// 向迭代器位置插入新的元素 //list::iterat
2009-05-03 18:26:00
351
原创 deque的基本操作
#include #include using namespace std;int main(int argc,int **argv){ deque d; d.push_back(1); d.push_back(2); d.push_back(3); d.push_back(4); d.push_back(5);//从头部插入元素 //d.push_front(10); //d.push_
2009-05-03 09:38:00
1586
原创 multimap的基本操作
#include #include #include using namespace std;//struct info //{// string name;// float score;// bool operator // return a.score // }//};//int main(int argc,int **argv){////map元素的创建、插入、遍历// map
2009-05-03 08:54:00
1492
原创 multiset的基本操作
#include #include #include using namespace std;int main(int argc,int **argv){ multiset ms; ms.insert("abc"); ms.insert("123"); ms.insert("111"); ms.insert("aaa"); ms.insert("aaa"); ms.insert("123
2009-05-02 19:52:00
492
原创 set的基本操作
#include #include #include using namespace std;//元素不是结构体,自定义比较函数如下://struct comp//{// bool operator()(const int &a,const int &b){// return a > b;// }//};//集合内元素是结构体,可以将比较函数写在结构体内:struct info { st
2009-05-02 19:33:00
579
原创 string的基本操作
//字符串的基本操作#include #include using namespace std;int main(int argc,int **argv){//直接给字符串对象赋值 //string s; //s = "hello,STL"; //cout//把字符串指针赋给一个字符串对象 //string s; //char ss[1000]; //cin>>ss; //
2009-05-02 12:56:00
325
原创 vector基本操作
#include #include #include using namespace std;int main(){//容器的创建 vector v; v.push_back(2); v.push_back(7); v.push_back(9); //v[0] = 2; //v[1] = 7; //v[2] = 9; for(vector::iterator iter = v.b
2009-04-30 19:58:00
574
原创 用字符串作为函数模版的实参
#include #include using namespace std;template void ref(T const& x){ cout}template void nonref(T x){ cout}int main(){ ref("hello"); nonref("hello");}//输出结果://x in ref(T const&):char cons
2009-04-20 11:27:00
580
原创 STL最简单的一例
#include #include#include #include using namespace std; int main(){ vector V; string tmp; while (getline(cin,tmp)) V.push_back(tmp); sort(V.begin(),V.end()); copy(V.begin(),V.end(),o
2009-04-17 18:19:00
236
原创 模版重载
"max.h" #include templateinline T const& maxOfObject(T const& a,T const& b){ return a>b?a:b;}templateinline T const& maxOfObject(T const& a,T const& b,T const& c){ return maxOfObject(maxOfObje
2009-04-17 13:47:00
267
原创 模版的简单使用
#include "max.h"template inline T const& maxTwoObject(T const& a, T const& b){ return a>b?a:b;} #include "max.h"#include #include using namespace std;int main(){ int i = 42; cout doub
2009-04-17 11:04:00
253
原创 map的使用:
#include #include #include #include #include #include using namespace std;ifstream& open_file(ifstream& in,const string& file);int main(int argc,char **argv){ map transmap; string key,val
2009-04-16 19:45:00
403
原创 程序員的成長六個階段
一個程序員的成長六個階段 第一階段 此階段主要是能熟練地使用某種語言。 這就相當於練武中的套路和架式這些表面的東西。 第二階段 此階段能精通基於某種平臺的介面 (例如我們現在常用的Win 32的API函數) 以及所對應語言的自身的庫函數。 到達這個階段後,也就相當於可以進行真實散打對練了, 可以真正地在實踐中做些應用。 第三階段 此階段能深入地瞭解某個平臺系統的底層, 已經具有了初級的內功的能力,
2009-04-15 13:54:00
667
原创 c++流
#include#include #include #include using namespace std;int fileToVector(string fileName ,vector& svec){ ifstream inFile(fileName.c_str()); if(!inFile) return 1; string s; while (inFile >> s) svec
2009-04-11 13:29:00
307
原创 C++之父Bjarne谈C++中的STL模板
C++之父Bjarne谈C++中的STL模板 在1994年,我主要关心的是如何使ISO C++标准尽可能地好--同时在它所包含的特性和规范的质量两个方面--并获得多数人的同意。即使人们不接受某种规范,也不会影响它(规范)的良好性。ISO标准没有强制力,因此有些人认为自己不值得浪费时间来适应它,除非(群体)社团的压力能够使他们确信该规范的价值。对于一个实现者来说,适应环境是很重要的额外工作,因此
2009-04-08 10:57:00
945
原创 多重继承和纯抽象类
多重继承和纯抽象类 Bill Venners:我在1991至1996这5年间,几乎一直 仅仅使用C++编程。在那时,我认为多重继承唯一目的就是让我能够从多个基类中继承它们各自的数据和函数 — 不管是虚 拟函数还是非虚拟函数。那时候,我和我使用C++的同事几乎从未想过可以使用一种不含任何数据而仅包含 纯虚函数的类,也就是现在Java中被称为接口的东西。最近您好像又越来越多地提起了抽象类这个概念,
2009-04-08 10:33:00
3060
2
原创 Bjarne访谈:抽象与效率
提升抽象的层面 Bill Venners(以下简称Bill):我最初是从Borland的一个教学录像“World of C++"”开始学习C++的。在该录像开头的简短片断中,你说你正致力于C++方面的工作是提升编程过程中的抽象层面。 Bjarne Stroustrup(以下简称BS):是的。 Bill:提升抽象层面意味着什么呢,一个高的抽象层面为什么会有良好 的表现呢? BS:较高
2009-04-08 10:30:00
419
翻译 C++风格与技巧(Bjarne Stroustrup著)
目录:我如何写这个非常简单的程序?为什么编译要花这么长的时间?为什么一个空类的大小不为0?我必须在类声明处赋予数据吗?为什么成员函数默认不是virtual的?为什么析构函数默认不是virtual的?为什么不能有虚拟构造函数?为什么重载在继承类中不工作?我能够在构造函数中调用一个虚拟函数吗?有没有“指定位置删除”(placement delete)?我能防止别人继承我自己的类吗?为什么不能为模板参数
2009-04-08 10:25:00
415
转载 c++四书五经
C++是一门广泛用于工业软件研发的大型语言。它自身的复杂性和解决现实问题的能力,使其极具学术研究价值和工业价值。和C语言一样,C++已经在许多重要的领域大获成功。 然而,一个不可否认的现实是,在低阶程序设计领域,C++挤压着C同时也在承受着C的强烈反弹,而在高阶程序设计领域,Java和C#正在不断蚕食着C++的地盘。也许C++与C合为一体永远都是一个梦想,也许Java和C#的狂潮终将迫使C
2009-04-08 10:03:00
590
原创 c++书籍
推荐C++教程1. > , Bjarne Stroustrup 这是一本每个人都应该买但不一定要看的书,强烈建议初学者不要看这本书,否则可能会一头雾水,失去信心,BS写书本来就不怎么样,他自己都说他的书有些晦涩难懂,但是买一本放在书柜里,有什么不清楚的地方查查高人如何解析还是有必要的。中文版是裘老师翻译的,以裘老师的深厚功力,技术上大家大可放心,但语言流畅上我就不敢认同了,况且这还是一本大书,
2009-04-08 09:41:00
702
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人