面向对象C++
豌豆射手GCC
这个作者很懒,什么都没留下…
展开
-
贪心算法+容器list+advance 406. 根据身高重建队列
406. 根据身高重建队列假设有打乱顺序的一群人站成一个队列。 每个人由一个整数对(h, k)表示,其中h是这个人的身高,k是排在这个人前面且身高大于或等于h的人数。 编写一个算法来重建这个队列。注意:总人数少于1100人。示例输入:[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]输出:[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]解题先对people进行排序——h从大小,若相等,则k从小到大;按顺序将peopl原创 2020-05-22 14:11:49 · 275 阅读 · 0 评论 -
C++ 井字棋
井字棋两个玩家,一个打圈,一个打叉,轮流在3乘3的格上打自己的符号,最先以横、直、斜连成一线则为胜。如果双方都下得正确无误,将得和局。参考如下:项目分析需要的函数1.play函数——制定游戏规则包括下棋的顺序,输赢的确定,棋盘的布置,下棋的方法,一局游戏结束后的输出2.draw函数——输出游戏棋盘棋盘位置不变,故使用 COORD c = { 0, 2 }; SetConsol...原创 2020-04-02 15:07:52 · 5159 阅读 · 0 评论 -
C++ map的派生 004:编程填空:数据库内的学生信息
004:编程填空:数据库内的学生信息描述程序填空,使得下面的程序,先输出(Tom,80),(Tom,70),(Jone,90),(Jack,70),(Alice,100),(Tom,78),(Tom,78),(Jone,90),(Jack,70),(Alice,100),(70,Jack),(70,Tom),(80,Tom),(90,Jone),(100,Alice),(70,E...原创 2020-04-01 14:18:41 · 1032 阅读 · 0 评论 -
C++multimap 003:冷血格斗场
003:冷血格斗场描述为了迎接08年的奥运会,让大家更加了解各种格斗运动,facer新开了一家冷血格斗场。格斗场实行会员制,但是新来的会员不需要交入会费,而只要同一名老会员打一场表演赛,证明自己的实力。我们假设格斗的实力可以用一个正整数表示,成为实力值,两人的实力值可以相同。另外,每个人都有一个唯一的id,也是一个正整数。为了使得比赛更好看,每一个新队员都会选择与他实力最为接近的人比赛,即比...转载 2020-04-01 14:15:02 · 918 阅读 · 2 评论 -
C++ set mutiset 001:Set
001:Set描述现有一整数集(允许有重复元素),初始为空。我们定义如下操作:add x 把x加入集合del x 把集合中所有与x相等的元素删除ask x 对集合中元素x的情况询问对每种操作,我们要求进行如下输出。add 输出操作后集合中x的个数del 输出操作前集合中x的个数ask 先输出0或1表示x是否曾被加入集合(0表示不曾加入),再输出当前集合中x的个数,中间用空格格开。...原创 2020-03-31 21:47:37 · 409 阅读 · 0 评论 -
C++ map 002:热血格斗场
002:热血格斗场描述为了迎接08年的奥运会,让大家更加了解各种格斗运动,facer新开了一家热血格斗场。格斗场实行会员制,但是新来的会员不需要交入会费,而只要同一名老会员打一场表演赛,证明自己的实力。我们假设格斗的实力可以用一个正整数表示,成为实力值。另外,每个人都有一个唯一的id,也是一个正整数。为了使得比赛更好看,每一个新队员都会选择与他实力最为接近的人比赛,即比赛双方的实力值之差的绝...原创 2020-03-31 21:32:15 · 740 阅读 · 0 评论 -
C++ 模板类函数——ostream 006:我自己的 ostream_iterator
描述程序填空输出指定结果#include <iostream>#include <list>#include <string>using namespace std;template <class T1,class T2>void Copy(T1 s,T1 e, T2 x){ for(; s != e; ++s,++x) *x...原创 2020-03-31 00:33:22 · 571 阅读 · 0 评论 -
C++ 可赋参数的函数对象 004:函数对象的过滤器 005:白给的list排序
004:函数对象的过滤器描述程序填空输出指定结果#include <iostream>#include <vector>using namespace std;struct A { int v; A() { } A(int n):v(n) { }; bool operator<(const A & a) const { return...原创 2020-03-31 00:23:45 · 596 阅读 · 0 评论 -
C++ 模板函数 自定义sort 002:按距离排序
002:按距离排序描述程序填空,输出指定结果#include <iostream>#include <cmath>#include <algorithm>#include <string>using namespace std;template <class T1,class T2>struct Closer {// ...原创 2020-03-31 00:13:20 · 867 阅读 · 0 评论 -
C++ 模板函数copy 001:goodcopy
001:goodcopy描述编写GoodCopy类模板,使得程序按指定方式输出#include <iostream>using namespace std;template <class T>struct GoodCopy {// 在此处补充你的代码};int a[200];int b[200];string c[200];string d[2...原创 2020-03-31 00:06:14 · 542 阅读 · 0 评论 -
C++ STL list vector 007:List
描述写一个程序完成以下命令:new id ——新建一个指定编号为id的序列(id<10000)add id num——向编号为id的序列加入整数nummerge id1 id2——合并序列id1和id2中的数,并将id2清空unique id——去掉序列id中重复的元素out id ——从小到大输出编号为id的序列中的元素,以空格隔开输入第一行一个数n,表示有多少个命令( n...原创 2020-03-30 23:39:22 · 376 阅读 · 0 评论 -
C++ 模板类中的模板类 003:很难蒙混过关的CArray3d三维数组模板类
描述实现一个三维数组模版CArray3D,可以用来生成元素为任意类型变量的三维数组,输出指定结果#include <iostream>#include <iomanip> #include <cstring>using namespace std;template <class T>class CArray3D{// 在此处补充你的...原创 2020-03-30 19:35:34 · 1417 阅读 · 0 评论 -
C++ 模板函数 001:简单的SumArray 002 简单的foreach 003 简单的Filter 006 这个模板并不难
001:简单的SumArray描述填写模板 PrintArray,使得程序输出结果是: TomJackMaryJohn 10 不得编写SumArray函数#include <iostream>#include <string>using namespace std;template <class T>T SumArray(// 在此处补充你的代码...原创 2020-03-29 14:10:33 · 2055 阅读 · 0 评论 -
C++类模板 004:你真的搞清楚为啥 while(cin >> n) 能成立了吗? bool成员的重载
004:你真的搞清楚为啥 while(cin >> n) 能成立了吗?描述读入两个整数,输出两个整数 ,直到碰到-1#include <iostream>using namespace std;class MyCin{// 在此处补充你的代码};int main(){ MyCin m; int n1,n2; while( m &g...原创 2020-03-29 13:55:16 · 1944 阅读 · 0 评论 -
C++ 模板函数 007:排序,又见排序!
007:排序,又见排序!描述自己编写一个能对任何类型的数组进行排序的mysort函数模版。只能写一个mysort模板,不能写mysort函数!#include <iostream>using namespace std;bool Greater2(int n1,int n2) { return n1 > n2;}bool Greater1(int n1,int...原创 2020-03-29 13:37:32 · 951 阅读 · 0 评论 -
C++ 模板类 005:山寨版istream_iterator
005:山寨版istream_iterator描述模仿C++标准模板库istream_iterator用法,实现CMyistream_iterator使得程序按要求输出#include <iostream>#include <string>using namespace std;template <class T>class CMyistream...原创 2020-03-29 12:34:18 · 780 阅读 · 0 评论 -
C++ 多态 001:看上去像多态 002:Fun和Do 003:这是什么鬼delete 004:怎么又是Fun和Do
001:看上去像多态描述程序填空产生指定输出#include <iostream>using namespace std;class B { private: int nBVal; public: void Print() { cout << "nBVal="<< nBVal << endl; } void ...原创 2020-03-28 11:21:51 · 1276 阅读 · 0 评论 -
C++ 魔兽世界之二:装备
总时间限制: 1000ms 内存限制: 65536kB描述魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。红司令部,City 1,City 2,……,City n,蓝司令部两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值这两种属性。有的武士可以拥有武器。武器有三种,...原创 2020-03-27 12:37:30 · 857 阅读 · 0 评论 -
C++ 继承 002:继承自string的MyString 004:编程填空:统计动物数量
002:继承自string的MyString描述程序填空,输出指定结果#include <cstdlib>#include <iostream>#include <string>#include <algorithm>using namespace std;class MyString:public string{// 在此处补充...原创 2020-03-26 15:27:33 · 1008 阅读 · 0 评论 -
C++ 继承 001:全面的MyString
001:全面的MyString描述程序填空,输出指定结果#include <cstdlib>#include <iostream>using namespace std;int strlen(const char * s) { int i = 0; for(; s[i]; ++i); return i;}void strcpy(char * d,con...原创 2020-03-26 14:49:26 · 805 阅读 · 3 评论 -
C++ 运算符重载 005:别叫,这个大整数已经很简化了!
005:别叫,这个大整数已经很简化了!总时间限制: 1000ms 内存限制: 65536kB描述程序填空,输出指定结果#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> using namespace std;const int MA...原创 2020-03-25 13:41:07 · 605 阅读 · 0 评论 -
C++ 运算符重载 用一维数组表示二维数组 004:第四周程序填空题3
004:第四周程序填空题3总时间限制: 1000ms 内存限制: 65536kB描述写一个二维数组类 Array2,使得下面程序的输出结果是:0,1,2,3,4,5,6,7,8,9,10,11,next0,1,2,3,4,5,6,7,8,9,10,11,程序:#include <iostream>#include <cstring>...原创 2020-03-25 13:30:10 · 838 阅读 · 8 评论 -
C++运算符重载 003:惊呆!Point竟然能这样输入输出
003:惊呆!Point竟然能这样输入输出总时间限制: 1000ms 内存限制: 65536kB描述程序填空#include <iostream> using namespace std;class Point { private: int x; int y; public: Point() { };// 在此处补充你的代码}; int ma...原创 2020-03-25 00:17:46 · 1024 阅读 · 0 评论 -
C++ 运算符重载 002:看上去好坑的运算符重载
002:看上去好坑的运算符重载描述程序填空#include <iostream> using namespace std;class MyInt { int nVal; public: MyInt( int n) { nVal = n ;}// 在此处补充你的代码}; int Inc(int n) { return n + 1;}int main (...原创 2020-03-25 00:13:27 · 636 阅读 · 0 评论 -
C++ 运算符重载001:MyString
001:MyString描述补足MyString类,使程序输出指定结果#include <iostream>#include <string>#include <cstring>using namespace std;class MyString { char * p;public: MyString(const char * s) { ...原创 2020-03-24 23:31:04 · 556 阅读 · 0 评论 -
C++ 魔兽世界之一:备战
005:魔兽世界之一:备战总时间限制: 1000ms 内存限制: 65536kB描述魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。红司令部,City 1,City 2,……,City n,蓝司令部两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值、攻击力这三种属性。...原创 2020-03-24 00:35:17 · 1392 阅读 · 3 评论 -
C++ 类和对象提高
001:返回什么才好呢总时间限制: 1000ms 内存限制: 65536kB描述程序填空,使其按要求输出#include <iostream>using namespace std;class A {public: int val; A(int// 在此处补充你的代码};int main(){ int m,n; A a; cout << a...原创 2020-03-22 23:57:19 · 245 阅读 · 0 评论 -
C++ 构造函数 001:编程填空:学生信息处理程序
001:编程填空:学生信息处理程序总时间限制: 1000ms 内存限制: 1024kB描述实现一个学生信息处理程序,计算一个学生的四年平均成绩。要求实现一个代表学生的类,并且类中所有成员变量都是【私有的】。补充下列程序中的 Student 类以实现上述功能。#include <iostream>#include <string>#include <cs...原创 2020-03-21 23:59:58 · 679 阅读 · 0 评论 -
C++ 构造函数 002:奇怪的类复制
002:奇怪的类复制总时间限制: 1000ms 内存限制: 65536kB描述程序填空,使其输出9 22 5#include <iostream>using namespace std;class Sample {public: int v;// 在此处补充你的代码};void PrintAndDouble(Sample o){ cout << o...原创 2020-03-21 23:56:12 · 392 阅读 · 0 评论 -
C++ 结构函数 003:超简单的复数类
003:超简单的复数类总时间限制: 1000ms 内存限制: 65536kB描述下面程序的输出是:3+4i5+6i请补足Complex类的成员函数。不能加成员变量。#include <iostream>#include <cstring>#include <cstdlib>using namespace std;class Complex ...原创 2020-03-21 23:52:37 · 422 阅读 · 1 评论 -
C++ 构造函数 004:哪来的输出
004:哪来的输出总时间限制: 1000ms 内存限制: 65536kB描述程序填空,输出指定结果#include <iostream>using namespace std;class A { public: int i; A(int x) { i = x; }// 在此处补充你的代码};int main(){ A a(1); A * pa = ne...原创 2020-03-21 23:49:03 · 360 阅读 · 0 评论 -
C++动态内存 004:神秘的数组初始化
004:神秘的数组初始化描述填空,使得程序输出指定结果#include <iostream>using namespace std;int main(){ int * a[] = {// 在此处补充你的代码0,0 ,new int, new int[10] }; *a[2] = 123; a[3][5] = 456; if(! a[0] ) { c...原创 2020-03-20 15:36:44 · 347 阅读 · 1 评论 -
C++引用 好怪异的返回值
好怪异的返回值描述填空,使得程序输出指定结果#include <iostream>using namespace std;// 在此处补充你的代码 int &//getElement(int * a, int i){ return a[i];}int main(){ int a[] = {1,2,3}; getElement(a,1) = 10...原创 2020-03-20 15:25:39 · 533 阅读 · 0 评论 -
C++引用 难一点的swap
难一点的swap函数内部为实参的copy,所以地址的copy交换对原地址没有改变;需要将地址的copy引用地址,进行地址交换,才会改变原地址;填空,使得程序输出结果是:5,3#include <iostream>using namespace std;void swap(//在此输入代码int *&a,int *&b ){ ...原创 2020-03-20 15:17:57 · 244 阅读 · 0 评论