当前位置: 首页 > news >正文

C++从入门到精通 第十六章(STL常用算法)

 写在前面:

  1. 本系列专栏主要介绍C++的相关知识,思路以下面的参考链接教程为主,大部分笔记也出自该教程,笔者的原创部分主要在示例代码的注释部分。
  2. 除了参考下面的链接教程以外,笔者还参考了其它的一些C++教材(比如计算机二级教材和C语言教材),笔者认为重要的部分大多都会用粗体标注(未被标注出的部分可能全是重点,可根据相关部分的示例代码量和注释量判断,或者根据实际经验判断)。
  3. 如有错漏欢迎指出。

参考教程:黑马程序员匠心之作|C++教程从0到1入门编程,学习编程不再难_哔哩哔哩_bilibili

一、概述

算法主要是由头文件<algorithm> <functional> <numeric>组成:

(1)<algorithm>是所有STL头文件中最大的一个,范围涉及到比较、交换、查找、遍历操作、复制、修改等等。

(2)<numeric>体积很小,只包括几个在序列上面进行简单数学运算的模板函数。

(3)<functional>定义了一些模板类,用以声明函数对象。

二、常用遍历算法

1、算法简介

for_each    //遍历容器

transform   //将容器中的元素搬运到另一个容器中

2、for_each

for_each(iterator beg, iterator end, _func);    //遍历容器

// beg——开始迭代器

// end——结束迭代器

// _func——函数或者函数对象

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;void print01(int val)
{cout << val << "  ";
}
class print02
{
public:void operator()(int val){cout << val << "  ";}
};void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}for_each(v.begin(), v.end(), print01);cout << endl;for_each(v.begin(), v.end(), print02());cout << endl;
}int main() {test01();system("pause");return 0;
}

3、transform

transform(iterator beg1, iterator end1, iterator beg2, _func);

// beg1——源容器开始迭代器

// end1——源容器结束迭代器

// beg2——目标容器开始迭代器

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;class Transform
{
public:int operator()(int v){return v;   //可以对v做运算,比如v+100}
};
class Print
{
public:void operator()(int v){cout << v << "  ";}
};void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}vector<int>vTarget;vTarget.resize(v.size());     //目标容器需要提前开辟空间transform(v.begin(), v.end(), vTarget.begin(), Transform());for_each(vTarget.begin(), vTarget.end(), Print());cout << endl;
}int main() {test01();system("pause");return 0;
}

三、常用查找算法

1、算法简介

find //查找元素

find_if //按条件查找元素

adjacent_find //查找相邻重复元素

binary_search //二分查找法

count //统计元素个数

count_if //按条件统计元素个数

//_func 函数或者函数对象

2、find

(1)功能描述:查找指定元素,找到返回指定元素的迭代器,找不到则返回结束迭代器end()。

(2)函数原型:

find(iterator beg, iterator end, value);  

// beg——开始迭代器

// end——结束迭代器

// value——查找的元素

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<string>void test01() 
{vector<int> v;for (int i = 0; i < 10; i++) {v.push_back(i + 1);}//查找容器中是否有 5 这个元素vector<int>::iterator it = find(v.begin(), v.end(), 5);if (it == v.end()){cout << "没有找到!" << endl;}else{cout << "找到:" << *it << endl;}
}class Person 
{
public:Person(string name, int age){this->m_Name = name;this->m_Age = age;}//重载==bool operator==(const Person& p){if (this->m_Name == p.m_Name && this->m_Age == p.m_Age){return true;}return false;}
public:string m_Name;int m_Age;
};void test02() 
{vector<Person> v;//创建数据Person p1("aaa", 10);Person p2("bbb", 20);Person p3("ccc", 30);Person p4("ddd", 40);v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);vector<Person>::iterator it = find(v.begin(), v.end(), p2);if (it == v.end()){cout << "没有找到!" << endl;}else{cout << "找到姓名:" << it->m_Name << " 年龄: " << it->m_Age << endl;}
}int main() {test01();test02();system("pause");return 0;
}

3、find_if

(1)功能描述:按条件查找元素,找到返回指定位置迭代器,找不到返回结束迭代器位置。

(2)函数原型:

find_if(iterator beg, iterator end, _Pred);   

// beg——开始迭代器

// end——结束迭代器

// _Pred——函数或者谓词(返回bool类型的仿函数)

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;class GreaterFive
{
public:bool operator()(int val){return val > 5;}
};void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}vector<int>::iterator it;it = find_if(v.begin(), v.end(), GreaterFive());if (it == v.end()){cout << "没有找到大于5的数" << endl;}else{cout << *it << endl;}
}class Person
{
public:int m_Age;string m_Name;Person(int age, string name){this->m_Age = age;this->m_Name = name;}
};
class Greater20
{
public:bool operator()(Person &p){return p.m_Age > 20;}
};
void test02()
{vector<Person>v;Person p1(10 ,"aaa");Person p2(20 ,"bbb");Person p3(30 ,"ccc");Person p4(40 ,"ddd");v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);vector<Person>::iterator it;it = find_if(v.begin(), v.end(), Greater20());if (it == v.end()){cout << "没有找到年龄大于20的人" << endl;}else{cout << "找到力" << endl;}
}int main() {test01();test02();system("pause");return 0;
}

4、adjacent_find

(1)功能描述:查找相邻重复元素,返回相邻元素的第一个位置的迭代器。

(2)函数原型:

adjacent_find(iterator beg, iterator end);   

// beg——开始迭代器

// end——结束迭代器

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void test01() 
{vector<int> v;v.push_back(0);v.push_back(2);v.push_back(0);v.push_back(3);v.push_back(1);v.push_back(4);v.push_back(3);v.push_back(3);v.push_back(0);vector<int>::iterator it;it = adjacent_find(v.begin(), v.end());if (it == v.end()){cout << "未找到相邻重复元素" << endl;}else{cout << "找到相邻重复元素" << *it << endl;}
}int main() {test01();system("pause");return 0;
}

5、binary_search

(1)功能描述:查找指定元素是否存在,查到就返回true,否则返回false。

(2)函数原型:

bool binary_search(iterator beg, iterator end, value);   

// beg——开始迭代器

// end——结束迭代器

// value——查找的元素

// 注意: 虽然它查找效率高,但是在无序序列中不可用

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void test01() 
{vector<int> v;for (int i = 0; i < 10; i++){v.push_back(i);   //如果容器不是有序的序列,那么返回的结果可能会不准确}bool ret = binary_search(v.begin(), v.end(), 9);if (ret){cout << "找到元素9" << endl;}else{cout << "未找到元素9" << endl;}
}int main() {test01();system("pause");return 0;
}

6、count

(1)功能描述:统计元素个数(统计元素出现次数)。

(2)函数原型:

count(iterator beg, iterator end, value);  

// beg——开始迭代器

// end——结束迭代器

// value——统计的元素

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void test01() 
{vector<int> v;v.push_back(1);v.push_back(2);v.push_back(4);v.push_back(5);v.push_back(3);v.push_back(4);v.push_back(4);cout << "4元素个数为" << count(v.begin(), v.end(), 4) << endl;
}class Person
{
public:int m_Age;int m_Age2;Person(int a1, int a2){m_Age = a1;m_Age2 = a2;}bool operator==(const Person &p){if (m_Age2 == p.m_Age2){return true;}else{return false;}}
};
void test02()
{vector<Person>v;Person p1(1, 10);Person p2(1, 10);Person p3(2, 10);Person p4(1, 20);v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);cout << "与p1同Age2的人数为" << count(v.begin(), v.end(), p1)-1 << endl;
}int main() 
{test01();test02();system("pause");return 0;
}

7、count_if

(1)功能描述:按条件统计元素个数(元素出现次数)。

(2)函数原型:

count_if(iterator beg, iterator end, _Pred);  

// beg——开始迭代器

// end——结束迭代器

// _Pred——谓词

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>class Greater4
{
public:bool operator()(int val){return val > 4;}
};
void test01() 
{vector<int> v;v.push_back(1);v.push_back(2);v.push_back(6);v.push_back(5);v.push_back(3);v.push_back(4);v.push_back(4);cout << "大于4的元素个数为" << count_if(v.begin(), v.end(), Greater4()) << endl;
}class Person
{
public:int m_Age;int m_Age2;Person(int a1, int a2){m_Age = a1;m_Age2 = a2;}bool operator==(const Person &p){if (p.m_Age2 == m_Age2){return true;}return false;}
};
class Greater15
{
public:bool operator()(const Person &p){return p.m_Age2 > 15;}
};
void test02()
{vector<Person>v;Person p1(1, 10);Person p2(1, 10);Person p3(2, 30);Person p4(1, 20);v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);cout << "Age2>15的人数为" << count_if(v.begin(), v.end(), Greater15()) << endl;
}int main() 
{test01();test02();system("pause");return 0;
}

四、常用排序算法

1、算法简介

sort            //对容器内元素进行排序

random_shuffle  //洗牌,指定范围内的元素随机调整次序

merge          //容器元素合并,并存储到另一容器中

reverse         //反转指定范围的元素

2、sort

(1)功能描述:对容器内元素进行排序。

(2)函数原型:

sort(iterator beg, iterator end, _Pred);  

// beg——开始迭代器

// end——结束迭代器

// _Pred——谓词

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;v.push_back(1);v.push_back(2);v.push_back(6);v.push_back(5);v.push_back(3);v.push_back(4);v.push_back(4);sort(v.begin(), v.end());for_each(v.begin(), v.end(), myPrint);cout << endl;sort(v.begin(), v.end(),greater<int>());   //改成降序for_each(v.begin(), v.end(), myPrint);cout << endl;
}int main() 
{test01();system("pause");return 0;
}

3、random_shuffle

(1)功能描述:洗牌,指定范围内的元素随机调整次序。

(2)函数原型:

random_shuffle(iterator beg, iterator end);    

// beg——开始迭代器

// end——结束迭代器

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<ctime>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;v.push_back(1);v.push_back(2);v.push_back(6);v.push_back(5);v.push_back(3);v.push_back(4);v.push_back(4);sort(v.begin(), v.end());              //升序排列for_each(v.begin(), v.end(), myPrint);cout << endl;random_shuffle(v.begin(), v.end());    //打乱for_each(v.begin(), v.end(), myPrint);cout << endl;
}int main() 
{srand((unsigned int)time(NULL));test01();system("pause");return 0;
}

4、merge

(1)功能描述:两个容器元素合并,并存储到另一容器中(两个容器必须是有序的)。

(2)函数原型:

merge(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest);     

// begx——容器x的开始迭代器

// endx——容器x的结束迭代器

// dest——目标容器的开始迭代器

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;vector<int> v2;for (int i = 0; i < 10; i++){v.push_back(i);v2.push_back(i + 1);}vector<int>v3;v3.resize(v.size() + v2.size());   //提前给目标容器分配空间merge(v.begin(), v.end(), v2.begin(), v2.end(), v3.begin());for_each(v3.begin(), v3.end(), myPrint);cout << endl;
}int main() 
{test01();system("pause");return 0;
}

5、reverse

(1)功能描述:将容器内指定范围的元素进行反转。

(2)函数原型:

reverse(iterator beg, iterator end);     

// beg——开始迭代器

// end——结束迭代器

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;v.push_back(10);v.push_back(30);v.push_back(20);v.push_back(50);v.push_back(40);for_each(v.begin(), v.end(), myPrint);cout << endl;reverse(v.begin(), v.end());   //首尾对调(反转)for_each(v.begin(), v.end(), myPrint);cout << endl;
}int main() 
{test01();system("pause");return 0;
}

五、常用拷贝和替换算法

1、算法简介

copy      //容器内指定范围的元素拷贝到另一容器中

replace    //将容器内指定范围的旧元素修改为新元素

replace_if  //容器内指定范围满足条件的元素替换为新元素

swap      //互换两个容器的元素

2、copy

(1)功能描述:容器内指定范围的元素拷贝到另一容器中。

(2)函数原型:

copy(iterator beg, iterator end, iterator dest);     

// beg——开始迭代器

// end——结束迭代器

// dest——目标容器的起始迭代器

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;v.push_back(10);v.push_back(30);v.push_back(20);v.push_back(50);v.push_back(40);vector<int>v2;v2.resize(v.size());copy(v.begin(), v.end(), v2.begin());for_each(v2.begin(), v2.end(), myPrint);cout << endl;
}int main() 
{test01();system("pause");return 0;
}

3、replace

(1)功能描述:将容器内指定范围的旧元素修改为新元素。

(2)函数原型:

replace(iterator beg, iterator end, oldvalue, newvalue);    

// beg——开始迭代器

// end——结束迭代器

// oldvalue——旧元素

// newvalue——新元素

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;v.push_back(10);v.push_back(30);v.push_back(20);v.push_back(50);v.push_back(40);v.push_back(20);replace(v.begin(), v.end(), 20, 60);for_each(v.begin(), v.end(), myPrint);cout << endl;
}int main() 
{test01();system("pause");return 0;
}

4、replace_if

(1)功能描述:将区间内满足条件的元素,替换成指定元素。

(2)函数原型:

replace_if(iterator beg, iterator end, _pred, newvalue);    

// beg——开始迭代器

// end——结束迭代器

// _pred——谓词

// newvalue——新元素

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void myPrint(int val)
{cout << val << " ";
}class Greater25
{
public:bool operator()(int val){return val > 25;   //大于25的元素全部替换为60}
};
void test01() 
{vector<int> v;v.push_back(10);v.push_back(30);v.push_back(20);v.push_back(50);v.push_back(40);v.push_back(20);replace_if(v.begin(), v.end(), Greater25(), 60);for_each(v.begin(), v.end(), myPrint);cout << endl;
}int main() 
{test01();system("pause");return 0;
}

5、swap

(1)功能描述:互换两个容器的元素(交换的容器元素类型要相同)。

(2)函数原型:

swap(container c1, container c2);    

// c1——容器1

// c2——容器2

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;vector<int> v2;for (int i = 0; i < 10; i++){v.push_back(i);v2.push_back(i + 100);}for_each(v.begin(), v.end(), myPrint);cout << endl;for_each(v2.begin(), v2.end(), myPrint);cout << endl;cout << "-----------------------" << endl;v.swap(v2);for_each(v.begin(), v.end(), myPrint);cout << endl;for_each(v2.begin(), v2.end(), myPrint);cout << endl;
}int main() 
{test01();system("pause");return 0;
}

六、常用算术生成算法

1、算法简介

算术生成算法属于小型算法,使用时包含的头文件为 <numeric>。

accumulate  //计算容器元素累计总和

fill         //向容器中添加元素

2、accumulate

(1)功能描述:计算区间内容器元素累计总和。

(2)函数原型:

accumulate(iterator beg, iterator end, value);   

// beg——开始迭代器

// end——结束迭代器

// value——起始值

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<numeric>void test01() 
{vector<int> v;for (int i = 0; i <= 100; i++){v.push_back(i);}cout << accumulate(v.begin(), v.end(), 1000) << endl;   //1000 + 容器v中元素的总和
}int main() 
{test01();system("pause");return 0;
}

3、fill

(1)功能描述:向容器中填充指定的元素。

(2)函数原型:

fill(iterator beg, iterator end, value);  

// beg——开始迭代器

// end——结束迭代器

// value——填充值

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<numeric>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v;v.resize(10);fill(v.begin(), v.end(), 100);for_each(v.begin(), v.end(), myPrint);
}int main() 
{test01();system("pause");return 0;
}

七、常用集合算法

1、算法简介

set_intersection  //求两个容器的交集

set_union       //求两个容器的并集

set_difference   //求两个容器的差集

2、set_intersection

(1)功能描述:求两个容器的交集(两个集合必须是有序序列),返回值是交集中最后一个元素的位置。

(2)函数原型:

set_intersection(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest);

// begx——容器x的开始迭代器

// endx——容器x的结束迭代器

// dest——目标容器的开始迭代器

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<numeric>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v1;vector<int> v2;for (int i = 0; i < 10; i++){v1.push_back(i);     //0-9v2.push_back(i + 5); //5-14}vector<int> v3;v3.resize(min(v1.size(), v2.size()));vector<int>::iterator itEnd = set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());for_each(v3.begin(), itEnd, myPrint);   //输出的是交集cout << endl;for_each(v3.begin(), v3.end(), myPrint);  //给v3开辟空间时可能会有多余cout << endl;
}int main() 
{test01();system("pause");return 0;
}

3、set_union

(1)功能描述:求两个集合的并集(两个集合必须是有序序列),返回值是并集中最后一个元素的位置。

(2)函数原型:

set_union(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest);

// begx——容器x的开始迭代器

// endx——容器x的结束迭代器

// dest——目标容器的开始迭代器

//目标容器需要开辟的空间大小为两个容器空间的相加结果

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<numeric>void myPrint(int val)
{cout << val << " ";
}void test01() 
{vector<int> v1;vector<int> v2;for (int i = 0; i < 10; i++){v1.push_back(i);     //0-9v2.push_back(i + 5); //5-14}vector<int> v3;v3.resize(v1.size() + v2.size());vector<int>::iterator itEnd = set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());for_each(v3.begin(), itEnd, myPrint);   //输出的是并集cout << endl;for_each(v3.begin(), v3.end(), myPrint);  //给v3开辟空间时可能会有多余cout << endl;
}int main() 
{test01();system("pause");return 0;
}

4、set_difference

(1)功能描述:求两个集合的差集(两个集合必须是有序序列),返回值是差集中最后一个元素的位置。

(2)函数原型:

set_difference(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest);

// begx——容器x的开始迭代器

// endx——容器x的结束迭代器

// dest——目标容器的开始迭代器

//目标容器需要开辟的空间大小为两个容器空间的较大值

#include<iostream>
using namespace std;
#include <vector>
#include <algorithm>class myPrint
{
public:void operator()(int val){cout << val << " ";}
};void test01()
{vector<int> v1;vector<int> v2;for (int i = 0; i < 10; i++) {v1.push_back(i);v2.push_back(i + 5);}vector<int> vTarget;//取两个里面较大的值给目标容器开辟空间vTarget.resize(max(v1.size(), v2.size()));//返回目标容器的最后一个元素的迭代器地址cout << "v1与v2的差集为: " << endl;vector<int>::iterator itEnd =set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), vTarget.begin());for_each(vTarget.begin(), itEnd, myPrint());cout << endl;cout << "v2与v1的差集为: " << endl;itEnd = set_difference(v2.begin(), v2.end(), v1.begin(), v1.end(), vTarget.begin());for_each(vTarget.begin(), itEnd, myPrint());cout << endl;
}int main() {test01();system("pause");return 0;
}

相关文章:

C++从入门到精通 第十六章(STL常用算法)

写在前面&#xff1a; 本系列专栏主要介绍C的相关知识&#xff0c;思路以下面的参考链接教程为主&#xff0c;大部分笔记也出自该教程&#xff0c;笔者的原创部分主要在示例代码的注释部分。除了参考下面的链接教程以外&#xff0c;笔者还参考了其它的一些C教材&#xff08;比…...

【海贼王的数据航海:利用数据结构成为数据海洋的霸主】时间复杂度 | 空间复杂度

目录 1 -> 算法效率 1.1 -> 如何衡量一个算法的好坏&#xff1f; 1.2 -> 算法的复杂度 2 -> 时间复杂度 2.1 -> 时间复杂度的概念 2.2 -> 大O的渐进表示法 2.3 -> 常见时间复杂度计算 3 -> 空间复杂度 4 -> 常见复杂度对比 1 -> 算法效…...

OpenTiny Vue 组件库适配微前端可能遇到的4个问题

本文由体验技术团队 TinyVue 项目成员岑灌铭同学创作。 前言 微前端是一种多个团队通过独立发布功能的方式来共同构建现代化 web 应用的技术手段及方法策略&#xff0c;每个应用可以选择不同的技术栈&#xff0c;独立开发、独立部署。 TinyVue组件库的跨技术栈能力与微前端十…...

jmeter 命令行启动 动态参数化

[Jmeter命令行参数] 一、在linux中&#xff0c;使用非gui的方式执行jmeter。若需更改参数&#xff0c;必须先编辑jmx文件&#xff0c;找到对应的变量进行修改&#xff0c;比较麻烦。因此&#xff0c;可以参数化一些常用的变量&#xff0c;直接在Jmeter命令行进行设置 二、参数…...

C++跨模块释放内存

linux一个进程只有一个堆&#xff0c;不要考虑这些问题&#xff0c;但是windows一个进程可能有多个堆&#xff0c;要在对应的堆上释放。 一&#xff0c; MT改MD 一个进程的地址空间是由一个可执行模块和多个DLL模块构成的&#xff0c;这些模块中&#xff0c;有些可能会链接到…...

jQuery浅析

jQuery 是一个快速、简洁的 JavaScript 库&#xff0c;旨在简化 HTML 文档遍历、事件处理、动画以及 Ajax 交互等功能。由 John Resig 在2006年创建&#xff0c;它极大地简化了JavaScript开发人员在处理网页文档、选择DOM元素以及执行各种效果和功能时的工作。 核心特性&#x…...

分班问题 、幼儿园分班(C语言)

题目 幼儿园两个班的小朋友排队时混在了一起&#xff0c;每个小朋友都知道自己跟前面一个小朋友是不是同班&#xff0c;请你帮忙把同班的小朋友找出来 小朋友的编号为整数&#xff0c;与前面一个小朋友同班用Y表示&#xff0c;不同班用N表示 输入 输入为空格分开的小朋友编号…...

QT 如何让多语言翻译变得简单,提高效率?

一.QT多语言如何翻译的? 在QT的多语言翻译过程中,分为两个步骤:第一步生成ts文件,第二步将ts文件翻译为qm文件。如果我们在需要多语言的情况下,qml经常使用qstr或者qwidget中使用tr等等,遍布许多个文件夹,在需要更新新的翻译时会很麻烦。整个工程收索并修改,效率十分低…...

线性代数:线性方程组解的结构

目录 齐次/非齐次方程组的解 Ax 0 的解的性质 定理 Ax b 的解的性质 相关证明 例1 例2 例3 齐次/非齐次方程组的解 Ax 0 的解的性质 定理 Ax b 的解的性质 相关证明 例1 例2 例3...

mysql之CRUD常见函数union查询

select select * from c insert 字段设置自增后&#xff0c;当我们指定增加一条数据后&#xff0c;往后增加的数据都会在该条数据后进行递增&#xff0c;但是可以认为的指定增加某条id不存在的数据 insert into c values(7,‘政治’) insert into c(c2) values(‘历史1’),(…...

开窗函数实践-实现两行记录之间计算时间差

一、需求背景 基于保密要求&#xff0c;不放原始表&#xff0c;新建测试表用来演示 insert into TEST0221 (采血人, 采血时间, 条码号, 病人ID) values (张三, to_date(21-02-2024 12:00:00, dd-mm-yyyy hh24:mi:ss), 2024001, 0001);insert into TEST0221 (采血人, 采血时间…...

String字符串的常见方法总结

目录 一、int length():返回字符串的长度 二、char charAt(int index):返回某索引处的字符 三、boolean isEmpty()&#xff1a;判断字符串是否为空 四、String toUpperCase():将字符转换成大写 五、String toLowerCase():将字符转换成小写 六、String trim():去除首尾空白…...

Postgresql源码(122)Listen / Notify与事务的联动机制

前言 Notify和Listen是Postgresql提供的不同会话间异步消息通信功能&#xff0c;例子&#xff1a; LISTEN virtual; NOTIFY virtual; Asynchronous notification "virtual" received from server process with PID 8448. NOTIFY virtual, This is the payload; Asy…...

QT 数据库的增加操作和画图 Win

第一步、先配置CMakeLists.txt 在CMakeLists.txt中添加 find_package(Qt6 REQUIRED COMPONENTS Sql) find_package(Qt6 REQUIRED COMPONENTS Charts)target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Sql) target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Charts)避…...

【JS逆向学习】同花顺(q.10jqka)补环境

逆向目标 目标网址&#xff1a;https://q.10jqka.com.cn/ 目标接口&#xff1a; https://q.10jqka.com.cn/index/index/board/all/field/zdf/order/desc/page/3/ajax/1/ 目标参数&#xff1a;cookie 逆向过程 老规矩&#xff0c;先分析网络请求&#xff0c;发现是 cookie 加…...

解决MobaXterm网络错误连接超时问题

报错页面&#xff1a; 报错原因&#xff1a; ①网络断开了 ②网络端口&#xff0c;端口号改变 解决办法&#xff1a; ①重新连接网络按R ②固定端口号 第一步&#xff1a;编辑------>虚拟机网络编辑器&#xff08;我的Linux在虚拟机里&#xff09; 第二步&#xff1a;用…...

突发!AI独角兽「竹间智能」被曝停工停产6个月

大家好我是二狗。 今天早上起来刷朋友圈&#xff0c;看到一张截图——AI创企竹间智能&#xff0c;宣称因为公司所处的经营环境艰难&#xff0c;部分部门和岗位将从即日起停工停产6个月。 图源&#xff1a;&#xff08;企服科学&#xff09; 下面是文字版&#xff1a; 由于公司…...

Qt应用软件【协议篇】GPIO控制LED灯

GPIO简介 GPIO(General Purpose Input/Output,通用输入输出)是一种通用的端口定义,在各种计算机、嵌入式系统和微控制器中广泛应用。通过GPIO,计算机或微控制器可以与外部世界进行交互,例如读取传感器数据或控制外部设备(如LED灯、电机等)。 GPIO的应用场景 按钮和开…...

vulfocus靶场搭建

vulfocus靶场搭建 什么是vulfocus搭建教程靶场配置场景靶场编排靶场优化 什么是vulfocus Vulfocus 是一个漏洞集成平台&#xff0c;将漏洞环境 docker 镜像&#xff0c;放入即可使用&#xff0c;开箱即用&#xff0c;我们可以通过搭建该靶场&#xff0c;简单方便地复现一些框架…...

Swift基础知识:30.Swift访问控制

在 Swift 中&#xff0c;访问控制&#xff08;Access Control&#xff09;是一种用于限制代码模块对其他代码模块的访问权限的机制。通过访问控制&#xff0c;可以控制代码中各个部分的可见性和可访问性&#xff0c;以便于提高代码的安全性、可维护性和可复用性。 访问级别 S…...

ElasticSearch聚合操作

目录 ElasticSearch聚合操作 基本语法 聚合的分类 后续示例数据 Metric Aggregation Bucket Aggregation ES聚合分析不精准原因分析 提高聚合精确度 ElasticSearch聚合操作 Elasticsearch除搜索以外&#xff0c;提供了针对ES 数据进行统计分析的功能。聚合(aggregation…...

普中51单片机学习(定时器和计数器)

定时器和计数器 51单片机有两组定时器/计数器&#xff0c;因为既可以定时&#xff0c;又可以计数&#xff0c;故称之为定时器/计数器。定时器/计数器和单片机的CPU是相互独立的。定时器/计数器工作的过程是自动完成的&#xff0c;不需要CPU的参与。51单片机中的定时器/计数器是…...

having子句

目录 having子句 having和where的区别 Oracle从入门到总裁:https://blog.csdn.net/weixin_67859959/article/details/135209645 现在要求查询出每个职位的名称&#xff0c;职位的平均工资&#xff0c;但是要求显示平均工资高于 200 的职位 按照职位先进行分组&#xff0c;同…...

STM32H7 系列 MCU 内部 SRAM

通过参看《STM32H7 参考手册》“2.4 Embedded SRAM”章节知道 The STM32H743/53xx and STM32H750xB 内存特性: Up to 864 Kbytes of System SRAM 128 Kbytes of data TCM RAM 64 Kbytes of instruction TCM RAM 4 Kbytes of backup SRAM 1.1 TCM SRAM TCM : Tightly-Coupled …...

备战蓝桥杯---动态规划(应用2(一些十分巧妙的优化dp的手段))

好久不见&#xff0c;甚是想念&#xff0c;最近一直在看过河这道题&#xff08;感觉最近脑子有点宕机QAQ&#xff09;&#xff0c;现在算是有点懂了&#xff0c;打算记录下这道又爱又恨的题。&#xff08;如有错误欢迎大佬帮忙指出&#xff09; 话不多说&#xff0c;直接看题&…...

从 git 分支中合并特定文件,而不是整个分支的内容

问题 在git 中&#xff0c;我们可以使用 git merge 命令&#xff0c;合并整个分支&#xff0c;覆盖当前分支的内容&#xff0c;但是有时候我们并不想这么做&#xff0c;而是想 merge 某个文件。那么下面提供两种办法。 方法一 使用 git checkout&#xff0c;从别的分支&#x…...

pycharm 远程运行报错 Failed to prepare environment

什么也没动的情况下&#xff0c;远程连接后运行是没问题的&#xff0c;突然在运行时就运行不了了&#xff0c;解决方案 清理缓存&#xff1a; 有时候 PyCharm 的内部缓存可能出现问题&#xff0c;可以尝试清除缓存&#xff08;File > Invalidate Caches / Restart&#xff0…...

(十二)【Jmeter】线程(Threads(Users))之setUp 线程组

简述 操作路径如下: 作用:在正式测试开始前执行预加载或预热操作,为测试做准备。配置:设置预加载或预热操作的采样器、循环次数等参数。使用场景:确保在正式测试开始前应用程序已经达到稳定状态,减少测试结果的偏差。优点:提供预加载或预热操作,确保测试的准确性。缺…...

代码随想录算法训练营第二十五天|216.组合总和III,17.电话号码的字母组合

目录 216.组合总和II 17.电话号码的字母组合 216.组合总和II 如果把 组合问题理解了&#xff0c;本题就容易一些了。 题目链接/文章讲解&#xff1a;代码随想录 视频讲解&#xff1a;和组合问题有啥区别&#xff1f;回溯算法如何剪枝&#xff1f;| LeetCode&#xff1a;216.…...

c#创建安装windows服务

背景:最近在做设备数据对接采集时,遇到一些设备不是标准的Service-Client接口,导致采集的数据不够准确;比如设备如果中途开关机后,加工的数量就会从0开始重新计数,因此需要实时监控设备的数据,进行叠加处理;考略到工厂设备比较多,实时监听接口的数据为每秒3次,因此将…...