- 博客(9)
- 收藏
- 关注
原创 多个数的最大公约数 描述
多个数的最大公约数描述 求多个正整数的最大公约数 输入 每个测试输入包含1个测试用例,格式为 第1行,数据的组数n 第2行,第一组数据(数据之间以逗号隔开), 第3行,第二组数据, ... 第n+1行,第n组数据 输出输出每组数据中的最大公约数 样例 输入输出318,27,15,33120,328,56,26478,143,260,523813#include <ios...
2018-04-13 22:11:30
374
原创 爬楼梯
上N阶楼梯,一次可以走两阶或一阶,问有多少种上楼方式。方法一:#include <iostream> #include <stdio.h> using namespace std; int sum=0; void f(int n){ if(n<=0){ if(n==0){ sum++; } cout<<endl; ret...
2018-04-13 20:57:57
191
原创 template
-类型成为参数-function template Perform similar operations on different types of data. eg: swap function templatetemplate <classT>void swap( T&x , T&y ){ T temp=x; x=y; y=temp; } -s...
2018-04-07 20:48:31
198
原创 读入字符串
#include <stdio.h>void main(){ char str[100]; scanf("%[^\n]",str);//直到输入回车键,读取才结束,当然不能超过a定义的大小,否则会出错。此命令与gets(str)效果一样。 printf("%s\n",str);}...
2018-04-05 20:46:06
489
原创 the copy constructor
-没有写拷贝构造函数,编译器会自动给一个,会拷贝每一个成员变量(member-wise copy, not byte-to-byte copy) 若成员变量有其他类的对象,会调用那个类的对象 若成员变量有指针或引用,会发生相应拷贝,指针指向同一个东西,引用捆绑同一个东西-if the copy constructor is like this: HowMany(HowMany o){...
2018-04-03 11:25:08
207
原创 reference
#include <iostream> using namespace std; class A{ public: A(int &a):y(a){ //y must be initialized in the initializer list } private: int &y; }; const int size=50; int array[siz...
2018-04-03 09:25:33
142
原创 向上造型
-B是A的子类,B的对象可以被当作A的对象来使用(upcast : the act of converting from a derived reference or pointer to a base class reference or pointer),多出来的东西当不存在-区别于类型转换(数据可能丢失)...
2018-04-01 21:13:18
540
原创 const
#include <iostream> using namespace std; class A{ public: A(int ii,int cii):i(ii),ci(ci){ } void f(){ //void f(A* this) cout<<"f()"<<endl; } void f() const{ //vo...
2018-03-31 15:55:54
146
原创 inherit,static
#include <iostream> using namespace std; class Test{ public: Test(){ cout<<"Test()"<<endl; cnt+=1; } ~Test(){ cout<<"~Test()"<<endl; } static vo
2018-03-31 14:42:46
191
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅