C++算法
算法相关
pistach
游戏探索小能手
展开
-
【C++知识点】一维数组与二维数组
数组的定义、数组的取值、数组的遍历实现:用二维数组画出地图// 2021.2.24数组.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ //数组:一组数据的集合 //一维数组的定义:数组类型+数组名称[元素个数] //int arr原创 2021-02-24 13:31:02 · 146 阅读 · 0 评论 -
【C++实现】传送门
切换地图// 贪吃蛇.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>#include <time.h>using namespace std;#define KEY_DOWN(vk_code) GetAsyncKeyState(vk_code)&0x8000?1:0int _tmain(int argc, _TCHAR* argv原创 2021-03-01 15:44:00 · 895 阅读 · 0 评论 -
【C++实现】容器
1、将贪吃蛇的蛇改为容器;2、将飞机大战中的子弹改为容器;3、用容器创建出飞机大战的敌机,实现敌机随机出现并向下运动。贪吃蛇的蛇改为容器// 贪吃蛇(容器).cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>#include <time.h>#include <vector>using namespace std;#defi原创 2021-03-03 11:22:12 · 159 阅读 · 0 评论 -
【C++实现】消息机制
入口类:创建出GameMap和ShopShop注册消息把回调函数传入(但不执行);GameMap发送消息,执行Shop注册时传入的回调函数。// 2021.4.8(消息机制).cpp : 定义控制台应用程序的入口点。//观察者模式#include "stdafx.h"#include "GameMap.h"#include "Shop.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ CGameMap* pGam原创 2021-06-17 15:05:48 · 1430 阅读 · 1 评论 -
【C++知识点】类的多态
// 2021.4.2(类的多态).cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;class CAnimal{public: CAnimal(){} ~CAnimal(){} //虚函数 virtual void cry(){ cout << "Animal cry!" <<原创 2021-04-08 15:23:19 · 82 阅读 · 0 评论 -
【C++知识点】类的静态成员变量
// 类的静态成员变量(函数)和单例.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>#include <string>using namespace std; class CStudent{public: CStudent(){ m_nCount++; } //静态成员函数 static int getCount原创 2021-04-08 15:22:37 · 482 阅读 · 0 评论 -
【C++实现】单例
// 单例.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>#include <string>using namespace std;class CGameMgr{public: ~CGameMgr(); //4.静态单例接口 static CGameMgr* getInstance(){ if (nullptr == m_s原创 2021-04-08 15:20:17 · 74 阅读 · 0 评论 -
【C++知识点】函数模板、绑定
1、函数变量void print(string strName){ //函数A cout << strName << endl;}int _tmain(int argc, _TCHAR* argv[]){ function<void(string)> func = print; //<void(string)> 函数类型(参数类型) func("A老师"); system("pause"); //输出结果:A老师}2、类的原创 2021-04-08 15:12:28 · 127 阅读 · 0 评论 -
【C++知识点】链表(整理)
链表的创建链表的遍历链表节点的添加链表节点的删除链表的创建 SNode* pNewNode = new SNode(); //创建新节点 cout << "请输入ID和名字" << endl; cin >> pNewNode->nID >> pNewNode->strName; pTailNode->pNext = pNewNode; //把创建的节点接到尾部(接) pTailNode = pNewNode; .原创 2021-03-23 16:00:46 · 233 阅读 · 0 评论 -
【C++知识点】值传递,引用传递,地址传递
// reference.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include <windows.h>#include <iostream>#include <vector>using namespace std;//函数声明void Swap1(int pNum1, int pNum2);void Swap2(int& pNum1, int& pNum2);void Swap3(int*原创 2021-03-23 13:46:59 · 154 阅读 · 0 评论 -
【C++知识点】指针(整理)
指针:某个变量的内存地址定义:指针类型* 指针名称int* pAge;&取地址符:用于获取某个变量的内存地址*取值符:用于获取某个指针的数据内容int nAge = 5;int* pAge = &nAge; //把变量的内存地址赋值给指针,整型的变量要用整型的指针可以通过指针所存的地址操作(访问、修改)该地址的内容cout<< *pAge;*pAge = 8;注意:指针在使用之前一定要保证其所存的地址是有效的。指针定义后如果没有给定一个可用的地址,原创 2021-03-23 13:42:27 · 129 阅读 · 1 评论 -
【C++知识点】容器:list容器、map容器
// 2021.3.23(stl容器).cpp : 定义控制台应用程序的入口点。//#include “stdafx.h”#include <windows.h>#include #include #include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){vector VecNum;VecNum.push_back(5);VecNum.push_back(6)原创 2021-03-23 13:16:18 · 224 阅读 · 0 评论 -
【C++知识点】结构体、构造函数
构造函数(推箱子)// 推箱子(构造函数).cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;#define KEY_DOWN(vk_code) GetAsyncKeyState(vk_code)&0x8000?1:0//使用枚举来控制箭头移动与菜单切换//枚举和结构体可以放在main函数外enum{原创 2021-03-08 14:01:50 · 836 阅读 · 0 评论 -
【C++算法题】随机输出字符串的文字
// 随机输出字符串的文字.cpp : 定义控制台应用程序的入口点。//// 飞机大战(敌机放子弹).cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>#include <vector>#include <time.h>#include <string>using namespace std;#define KE原创 2021-03-04 14:49:47 · 332 阅读 · 1 评论 -
【C++算法】排序算法
简单排序// 数组排序.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int arrNum[5] = { 5, 9, 3, 8, 6 }; for (int i = 0; i < 5; i++) //第一个 {原创 2021-03-04 14:11:10 · 46 阅读 · 1 评论 -
【C++算法题】输入圆的半径,求圆的面积
输入圆的半径,求圆的面积// variable.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ float fa = 0; float pie = 3.14; cout << "请输入圆的半径a:" <<原创 2021-02-24 13:47:30 · 5521 阅读 · 0 评论 -
【C++算法题】求三角形边长
键盘输入三角形的三条边,求出三角形的边长。注意:三角形的形成条件// variable.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ float fa = 0; float fb = 0; float fc = 0; cout原创 2021-02-24 13:42:26 · 1083 阅读 · 0 评论 -
【C++算法题】输入一个五位数,输出它的反转
输入一个五位数,输出它的反转#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ cout << "请输入一个五位数" << endl; int nNum = 0; cin >> nNum;//12532 int nResult = 0;原创 2021-02-24 10:05:20 · 1889 阅读 · 0 评论 -
【C++算法题】求1!+2!+3!+4!+5!+6!的值
求1!+2!+3!+4!+5!+6!的值// 作业1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<windows.h>#include<iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int ni; int nj=1; int nResult = 0; for (ni = 1; ni <= 6; ni++)原创 2021-02-24 13:54:11 · 2659 阅读 · 0 评论 -
【C++算法题】计算1+(1+2)+(1+2+3)+……+(1+2+……20)的值
// 作业1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<windows.h>#include<iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int ni,nj; int nResult = 0; for (ni = 1; ni <= 20; ni++) { for (nj = 1; nj <=.原创 2021-02-23 18:31:04 · 1729 阅读 · 0 评论 -
【C++算法题】输入一个五位数,依次输出各位数
输入一个五位数,依次输出各位数。// 作业3.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<windows.h>#include<iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int num = 0;//存储得到的整数 int nChu = 10000;//存储变化的值 int nNumber;//存储输入的值 c原创 2021-02-24 13:56:11 · 4755 阅读 · 0 评论