![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++编程
lann*
这个作者很懒,什么都没留下…
展开
-
upper_bound()函数的使用
【代码】upper_bound()函数的使用。原创 2022-10-22 15:42:10 · 430 阅读 · 1 评论 -
java、c++继承后的访问权限
java与c++中继承后成员的访问权限原创 2022-06-10 09:40:24 · 176 阅读 · 0 评论 -
C++仿函数对象
/* 函数对象 重载函数调用操作符的类,气对象常称为函数对象 函数对象使用重载的()时,行为类似函数调用,也叫仿函数 本质 函数对象(仿函数)是一个类,不是一个函数 特点 1.函数对象在使用时,可以像普通函数那样调用,可以有参数,可以有返回值 2.函数对象超出普通函数的概念,函数对象可以有自己的状态(类具有自己的属性) 3.函数对象可以作为参数传递*/class MyAdd {pu...原创 2022-04-07 16:08:59 · 91 阅读 · 0 评论 -
最大公约数gcd 最小公倍数lcm
// 最大公约数 辗转相除法int gcd(int a,int b) { if (a%b == 0) return b; gcd(b,a%b);}// 最小公倍数 借助gcdint lcm(int a, int b) { int tgcd = gcd(a, b); return a * b / tgcd;}int main(int argc, char* argv[]){ cout << gcd(24, 160) << endl; cout &.原创 2021-09-08 09:59:34 · 71 阅读 · 0 评论 -
delete[] 使用注意
若动态申请空间int*a=new int[10];int* b=new int[15];则使用delete[]时错误的写法:delete[] a,b; (只能释放a的资源,b得不到释放造成资源泄漏)正确的写法:delete[] a;delete[] b;原创 2021-05-26 15:59:20 · 299 阅读 · 0 评论 -
回溯与dfs的不同之处
深度优先遍历算法只有visited[i]=true的操作,而没有visited[i]=false的操作,确保所有的元素不会被第二次遍历;回溯算法既有visited[i]=true的操作,也有visited[i]=false的操作,保证了在枚举另一种可能解的时候程序可以得到执行。...原创 2021-05-07 21:50:40 · 112 阅读 · 0 评论 -
map索引的三种方式
#include <iostream>#include <map>using namespace std;int main(){ map<int,int> m; for (int i = 0; i < 10; i++){ m[i] = i*i; } map<int,int>::iterator iter; iter = m.begin(); while(iter != m.end(.转载 2021-03-01 14:25:30 · 3357 阅读 · 0 评论 -
csu-acm 1003 uc browser
#include <iostream>#include <string>#include <vector>#include <cstring>using namespace std;int main(){ vector<string> strs; string str; int num_line = ...原创 2020-05-04 01:21:12 · 179 阅读 · 0 评论 -
unique 及 erase 函数
int main(){ vector<int> a = { 1,3,3,3,4,5,6,6,7 }; vector<int>::iterator it_1 = a.begin(); vector<int>::iterator it_2 = a.end(); cout << "去重前的 a : "; for (int i = 0; i...原创 2020-04-16 18:16:17 · 330 阅读 · 0 评论 -
二维vector容器的初始化与遍历
int main(){ // 二维vector容器的初始化 int num = 0; // C++11 的初始化方式 vector<vector<unsigned int>> res = { { 7,4,3,6,5,0 }, {1,3,2}, {4,7,6,3,5}, {8,9,3,4},{4,7,6,3,5} }; for (int i = 0; i <...原创 2020-04-15 19:52:08 · 1039 阅读 · 0 评论 -
字符统计 c++
#include <iostream>#include <cstring>using namespace std;char str[] = "HuaJangHu-BuLiangRen!"; // 双引号初始化,字符串末尾自动添加结束符 \0int main(){ for (int i = 0; i<strlen(str); i++) { ...原创 2019-09-05 10:27:10 · 544 阅读 · 0 评论 -
c++ 打印n阶实心菱形
#include<iostream>using namespace std;// 打印n阶实心菱形int main(){ int n; // 0<n<10 cin >> n; int i, k, j; for ( i=1;i<n;i++) // 行数 { for ( j = 0; j < n-i; j++) ...原创 2019-08-30 15:17:24 · 497 阅读 · 0 评论