随笔分类 -  c/c++

【C++/C FAQ】如何使用scanf指定输入字符串的格式
摘要://input is like: 1234ffff,4,5int R,X,Y;scanf("%x,%d,%d",&R,&X,&Y); 阅读全文

posted @ 2011-06-25 00:46 speedmancs 阅读(487) 评论(0) 推荐(0)

【C++/C FAQ】如何输入和输出十六进制的整数
摘要:int x; scanf("%x",&x); printf("%08x",12); 阅读全文

posted @ 2011-06-25 00:30 speedmancs 阅读(783) 评论(0) 推荐(0)

【C++/C FAQ】如何格式化输出以0填充的定长整数
摘要:printf("%02d:%02d:%02dpm\n",12,0,0); 阅读全文

posted @ 2011-06-24 23:24 speedmancs 阅读(751) 评论(0) 推荐(0)

【C++FAQ】怎么输入一行字符串(可能带空格)
摘要:#include <iostream>#include <vector>#include <algorithm>#include <string>#include <map>#include <cmath>using namespace std;int main(){ string str; while (getline(cin,str)) { cout << str << endl; } return 0;} 阅读全文

posted @ 2011-06-24 18:27 speedmancs 阅读(486) 评论(0) 推荐(0)

【C++FAQ】怎么给结构体排序
摘要:使用stl中的sort,并重载要排序的结构体或类的<号即可。示例代码如下(pku1007题)#include <iostream>#include <vector>#include <algorithm>#include <string>#include <map>#include <cmath>using namespace std;//只有ACGT这几个数class DNAStr{public: bool operator < (const DNAStr& other) const{ if (inv 阅读全文

posted @ 2011-06-24 17:25 speedmancs 阅读(572) 评论(0) 推荐(0)

【C++FAQ】如何设定小数点后的显示位数
摘要:double avg = sum / 13;cout.setf(ios::fixed);cout.precision(4);cout << "$" << sum / 12 << endl; 阅读全文

posted @ 2011-06-24 15:37 speedmancs 阅读(702) 评论(0) 推荐(0)

c++ operator重载的例子
摘要:#include <iostream>using namespace std;class A{public: A(double _data = 0.0):data(_data){} A& operator = (const A& rhs) { data = rhs.data; return *this; } friend A operator + (const A& lhs,const A& rhs); friend A operator - (const A& lhs,const A& rhs); friend A operator 阅读全文

posted @ 2011-06-09 22:06 speedmancs 阅读(29686) 评论(0) 推荐(1)

【c++题目003】关于析构
摘要:Which statement is false? a) Destructors are called when a pointer is deleted. b) Destructors are called when an object goes out of scope. c) Destructors are called when a reference goes out of scope. d) A virtual destructor should be used if the class has virtual methods. e) Base class destruc... 阅读全文

posted @ 2011-06-04 16:39 speedmancs 阅读(258) 评论(0) 推荐(0)

【C++题目002】哪些不是STL的collection
摘要:Which of the following is not an STL collection?a) vectorb) listc) mapd) treee) set 当然是tree。前三个都很常用,map和set内部是红黑树。单独的tree在STL中没有。 阅读全文

posted @ 2011-06-04 15:54 speedmancs 阅读(211) 评论(0) 推荐(0)

【C++题目001】类的哪些部分不是由编译器自动生成的
摘要:Which of the following is not automatically generated by the compiler?a) default constructorb) copy constructorc)equality operator (op==)d) assignment operator (op=)e) destructor#include <iostream>#include <string>#include <assert.h>using namespace std;class A{};int _tmain(int argc 阅读全文

posted @ 2011-06-04 15:52 speedmancs 阅读(201) 评论(0) 推荐(0)

c++编写的算24程序
摘要:今天在大本营看到了一个人家写的24程序,感觉人家的思路非常清晰,于是自己也着手写了一个,顺便温习了一下标准c++。在我的程序中,使用了 stringstream类做parse,后缀表达式穷举所有可行解,而用中缀表达式计算用户输入的表达式。因为比较懒,当用户算不出来时,按出来的答案是个后缀表达式。 =============================================== 4.21更新 1.发现对后缀表达式的理解错了。修改了穷举算24的函数,穷举空间改为4!*4^3 * 5,其中3个操作符在长度为7的后缀表达式的可能位置为5种。 2.使用二叉树和堆栈实现了后缀表达式向... 阅读全文

posted @ 2010-04-20 22:16 speedmancs 阅读(1157) 评论(0) 推荐(0)

导航