C++基础
c++常见知识应用以及注意要点
Mr 种马
工资到位,四皇干废
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
库函数sort详解
sort函数用法 1.sort函数包含在头文件为#include的c++标准库中,调用标准库里的排序方法可以实现对数据的排序,但是sort函数是如何实现的,我们不用考虑! 2.sort函数的模板有三个参数: void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp); (1)第一个参数first:...原创 2020-05-01 22:19:35 · 2103 阅读 · 0 评论 -
lower_bound()的使用
头文件:algorithm lower_bound()返回值是一个迭代器,返回指向大于等于key的第一个值的位置 对象:有序数组或容器 数组中使用: #include <algorithm> #include <iostream> using namespace std; int main() { int a[]={1,2,3,4,5,7,8,9}; printf("%...原创 2020-04-16 11:44:14 · 228 阅读 · 0 评论 -
c++基础-数学相关应用
1.最大公约数 //辗转相除法 int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } 2.最小公倍数 int min_ab(int a,int b){ return a*b/gcd(a,b); } //a,b最小公倍数=a*b/最大公约数 3.素数 bool is_prime(int n){ for(int i=2;i*i...原创 2020-04-09 16:22:43 · 272 阅读 · 0 评论 -
c++基础-set
set:二叉搜索树维护的容器 #include <iostream> #include <set> using namespace std; int main(){ //声明 set<int> s; //插入元素 s.insert(1); s.insert(3); s.insert(5); //查找元素 set<int>::itera...原创 2020-04-08 22:16:00 · 150 阅读 · 0 评论 -
c++基础-优先队列
优先队列:取值,删除取最大值 #include <iostream> #include <queue> using namespace std; int main(){ //声明 priority_queue<int> pq; //插入元素 pq.push(3); pq.push(5); pq.push(1); //不断循环直到空为止 while...原创 2020-04-08 22:05:16 · 173 阅读 · 0 评论 -
c++基础-全排列函数
一.数组中使用 函数模板: next_permutation(arr, arr+size); 函数模板: prev_permutation(arr, arr+size); 解释:arr为数组,size为数组长度。 next_permutation(arr, arr+size);当有下一个较大值返回1,否则返回0。 prev_permutation(arr, arr+size);当有上一个较小...原创 2020-04-07 18:03:55 · 683 阅读 · 0 评论 -
c++基础-string常见操作
1.获取长度(length()) string str = "12345"; int l = str.length();//长度为5 2.拼接(+) string str1 = "hello"; string str2 = "world"; str1 = str1 + " " + str2;//str1="hello world" 3.添加(append) //尾部追加 string st...原创 2020-04-07 17:44:52 · 300 阅读 · 0 评论 -
c++基础-递归实例
1.阶乘 #include <iostream> using namespace std; long jiecheng(int n); int main(){ int k; int rs; cin>>k; rs=jiecheng(k); cout<<rs<<endl; return 0; } long jiecheng(int n){...原创 2020-04-07 17:34:42 · 205 阅读 · 0 评论 -
c++基础-进制转换
c++在关于进制转换基本操作如下: #include <iostream> #include <bitset> #include <cstdio> #include <cstdlib> using namespace std; int main(){ /*char buffer[20]; cin>>buffer; char ...原创 2020-04-07 17:30:59 · 775 阅读 · 0 评论 -
c++基础-栈
c++中栈的基本使用代码如下: #include <iostream> #include <stack> using namespace std; int main(){ stack<int> s; for(int i=2;i<10;i++){ s.push(i);//从栈顶加入 } cout<<s.size()<...原创 2020-04-07 17:29:05 · 134 阅读 · 0 评论 -
c++基础-队列
c++中队列基础操作如下代码: #include <iostream> #include <queue> using namespace std; int main(){ queue<int> q; for(int i=1;i<13;i++){ q.push(i);//从队尾加入元素 } cout<<q.size()&l...原创 2020-04-07 17:27:27 · 160 阅读 · 0 评论
分享