#include<Windows.h>
#include<iostream>
#include<algorithm>  // sort  swap   min   max   lower_bound upper_bound reverse
#include<string>
#include<vector>
#include<queue>  //队列  先进先出
#include<stack>   //   stack是先进后出
#include<set>
#include<map>

其实 这一堆头文件,可以用一个万能头文件代替#include<bits/stdc++.h>

#include<bits/stdc++.h>
using namespace std;
vector<int>v;
int main(){
 for(int i=1;i<=10;i++)
  v.push_back(i);                //在vector类中作用为在vector尾部加入一个数据。
 for(auto x : v)                   //auto  输出v中有定义的
  {
  cout<<x<<endl;
 }

#include<bits/stdc++.h>
using namespace std;
vector<int>v;
vector<int>::iterator iter;
int main(){
 for(int i=10;i>=1;i--)
  v.push_back(i);
 sort(v.begin(),v.end());    //排序,默认从小到大         //注意区间 v.begin(),v.end(),左闭右开
 for(auto x : v)
  cout<<x<<" ";
}

#include<bits/stdc++.h>
using namespace std;
vector<int>v;
vector<int>::iterator iter;
int main(){
 int a=10,b=20;
 cout<<a<<" "<<b<<endl;
 swap(a,b);              //交换
 cout<<a<<" "<<b<<endl;
}

#include<bits/stdc++.h>
using namespace std;
vector<int>v;
vector<int>::iterator iter;
int main(){
 int a=10,b=20;
 cout<<a<<" "<<b<<endl;
 a^=b;b^=a;a^=b;        //请记住  这是一个骚操作!!   交换a和b  两次 a^=b不一样
 cout<<a<<" "<<b<<endl;
}

#include<bits/stdc++.h>
using namespace std;
vector<int>v;
vector<int>::iterator iter;
int main(){
 int a[11];
 for(int i=1;i<=10;i++)
    v.push_back(i);
 int pos=lower_bound(v.begin(),v.end(),8)-v.begin();   //注意区间 v.begin(),v.end(),左闭右开
 cout<<pos<<endl;                      // -v.begin()为什么不能去掉 :格式
}
// lower_bound()返回一个 iterator
//它指向在[first,last)标记的有序序列中可以插入value,
//而不会破坏容器顺序的第一个位置,
//而这个位置标记了一个第一个不小于value 的值。               
//upper_bound  是第一个大于的     
//  lower_bound 和upper_bound 是二分  ,而二分只对有序的 
 
 
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;                 //直接定义string     比数组啥的好用
 cin>>s;
 cout<<s<<endl;
}
 
 
 
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
 cin>>s;
 reverse(s.begin(), s.end());        //反转顺序  
 cout<<s<<endl;
 return 0;
}
 
 
 
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s="123456";
 cout<<s<<endl;
 return 0;
}
 
 
 
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s="123456";
 cout<<s[1]<<endl;            //输出2
 return 0;
}
 
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s="123456",s2="qwe";
 cout<<s+s2<<endl;            //可以直接相加
 return 0;
}
 
 
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s="123456",s2="qwe",s3=s+s2;   //没有减号
 cout<<s3<<endl;
 return 0;
}
 
 
 
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main(){
 for(int i=1;i<=10;i++)
 {
  int x;cin>>x;
  if(a[x]==1) cout<<"YES"<<endl;      
  else cout<<"NO"<<endl;
  a[x]=1;         //如果此时输入的数字,没有出现过,那么输出no  并把这个数字标记为1,下次输入的时候,会输出yes
 }
 
 
#include<bits/stdc++.h>               //此程序等同上一个,       在这里引入集合set  
using namespace std;
set<int>s;          //  For里 1e7  就会超过1s  就会炸掉     10 的7次方
int main(){
 for(int i=1;i<=10;i++)
 {
  int x;cin>>x;
  if(!s.count(x))  cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  s.insert(x);
 }

 
 

在queup   prior  优先队列 输入的自动排序 从小到大

multiset<int >s     也是set 的一种形式,可以重复,从小到大自动排序

 
 

#include<bits/stdc++.h> 
using namespace std;
priority_queue<int>a;          //队列 先进先出
int main(){
 int b;
 for(int i=0;i<10;i++){
  cin>>b;
  a.push(b);
 }
 for(int i=0;i<10;i++){
 cout<<a.top()<<" ";
 a.pop();
 }   //取得队首元素操作top();   那 是最小的队首还是对大的:?
}
// 输入 1 52 4 3 88 66 44 77 121 100
//  输出  121 100 88 77 66 52 44 4 3 1
/*empty()      如果队列为空,则返回真
pop()    删除对顶元素,删除第一个元素
push()        加入一个元素
size()      返回优先队列中拥有的元素个数
top()     返回优先队列对顶元素,返回优先队列中有最高优先级的元素  */

10.3 c++ STL 初步的更多相关文章

  1. Go语言之Windows 10开发工具LiteIDE初步使用

    Intel Core i5-8250U,Windows 10家庭中文版,go version go1.11 windows/amd64,LiteIDE X34.1 在RUNOOB.COM的Go语言教程 ...

  2. 2020.2.27——STL初步

    注:本文主要针对STL中的常用的操作进行总结 目录: 1.swap 2.sort 3.reverse 4.min,max(比较简单,暂且略过) 5._gcd 6.lower_bound &&a ...

  3. (STL初步)不定长数组:vector

    STL是指C++的标准模板库.(存储着一些常用的算法和容器) vector是一个不定长数组.它把一些常用的操作”封装“在vector类型内部. 例如,a是一个vector.1对元素的操作有,可以用a. ...

  4. 【STL初步】不定长数组:vector + 集合:set + 映射:map

    一.vector 为了节省空间,有时我们会使用动态数组vector. 定义动态数组 vector<类型名>变量名 vector<int>que //定义que为一个int类型的 ...

  5. AcWing STL初步学习

    vector, 变长数组,倍增的思想 size() 返回元素个数 empty() 返回是否为空 clear() 清空 front()/back() push_back()/pop_back() beg ...

  6. STL初步学习(queue,deque)

    4.queue queue就是队列,平时用得非常多.栈的操作是只能是先进先出,与栈不同,是先进后出,与之后的deque也有区别.个人感觉手写队列有点麻烦,有什么head和tail什么的,所以说 STL ...

  7. STL初步学习(vector)

    前文 初三下学期进入新的学习,对于前两年的学习内容因为各种原因 上课打游戏,睡觉,看视频 已经遗忘,忘记如何使用,算是重新学习一次信息学,希望能尽快将以前的内容弥补上来,争取能在CSP-2020取得一 ...

  8. STL初步学习(set)

    2.set set可以看作一个集合,可以实现自动排序(升序)和去重 在许多题目中,都可以使用这个模板库,减少很多操作,例如P1923 第k小数,当然,这道题有很多奇奇怪怪的做法,分值都不同,之后会讲解 ...

  9. STL初步学习(map)

    3.map map作为一个映射,有两个参数,第一个参数作为关键值,第二个参数为对应的值,关键值是唯一的 在平时使用的数组中,也有点类似于映射的方法,例如a[10]=1,但其实我们的关键值和对应的值只能 ...

随机推荐

  1. 双向绑定Proxy VS Object.defineProperty

    Vue3.0的双向绑定将使用Proxy代替Object.defineProperty,据尤大说,速度提升了1倍. 本文我们来探讨一下Proxy对比Object.defineProperty究竟有哪些优 ...

  2. Java面试—消息队列

    消息队列面试题 题目来自于中华石杉,解决方案根据自己的思路来总结而得. 题目主要如下: 1. 为什么要引入消息队列? 消息队列的引入可以解决3个核心问题: 解耦 异步 削峰 解耦 在一个项目中,如果一 ...

  3. codewars--js--create phone number

    Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of th ...

  4. 嗅探、DNS劫持配合CS钓鱼

    本章节讲述的是嗅探和DNS劫持的利用 嗅探:同一个局域网下,原本应该丢弃的包,被保留下来,即使不开双向欺骗 Driftnet工具:Driftnet监视网络流量,抓取网络流量中的JPEG和GIF图像.这 ...

  5. 查找第K大的值

    这种题一般是给定N个数,然后N个数之间通过某种计算得到了新的数列,求这新的数列的第K大的值 POJ3579 题意: 用$N$个数的序列$x[i]$,生成一个新序列$b$. 新的序列定义为:对于任意的$ ...

  6. rxjs简单的Observable用例

    import React from 'react'; import { Observable } from 'rxjs'; const FlowPage = () => { const onSu ...

  7. 两种从 TensorFlow 的 checkpoint生成 frozenpb 的方法

    1. 从 ckpt-.data,ckpt-.index 和 .meta 生成 frozenpb import os import tensorflow as tf from tensorflow.py ...

  8. P2853 [USACO06DEC]牛的野餐Cow Picnic

    ------------------------- 长时间不写代码了,从学校中抽身出来真的不容易啊 ------------------------ 链接:Miku ----------------- ...

  9. <a>超链接标签,<button>按钮标签,实现返回跳转

    超链接: <a href=”#” onClick=”javascript :history.back(-1);”>返回上一页</a> <a href=”#” onClic ...

  10. Java商城秒杀系统的设计与实战视频教程(SpringBoot版)

    课程目标掌握如何基于Spring Boot构建秒杀系统或者高并发业务系统,以及构建系统时采用的前后端技术栈适用人群Spring Boot实战者,微服务或分布式系统架构实战者,秒杀系统和高并发实战者,中 ...