#include<iostream>
#include<list>
#include<iterator>
#include<algorithm>
using namespace std;
list<int> p;
int ii, jj;
bool op(int x) /*这个很重要*/
{
return x <= ii;
}
int main()
{
int n;
while(cin >> n)
{
for(int i = 0; i < n; i++)
{
int t;
cin >> t;
p.push_back(t);
}
int m;
cin >> m;
for(int i = 0; i < m; i++)
{
int t;
cin >> t;
switch (t)
{
case 1:
{
cin >> ii >> jj;
list<int>::iterator it = find(p.begin(), p.end(), ii);
if(it != p.end())
p.insert(++it, jj);
break;
}
case 2:
{
cin >> ii;
p.remove_if(op); // list<int>::iterator it = find(p.begin(), p.end(), ii);
// for(int i = ii; i >= 0; i--)
// p.remove(i); break;
}
case 3:
{
cin >> ii >> jj;
list<int>::iterator iit = find(p.begin(), p.end(), jj);
if(iit != p.end()) /*依据题目上的“注”*/
p.remove(ii);
list<int>::iterator it = find(p.begin(), p.end(), jj);
if(it != p.end())
p.insert(++it, ii);
break;
} }
} cout << p.front();
p.pop_front();
while(!p.empty())
{
cout << " " << p.front();
p.pop_front();
}
cout << endl;
}
return 0;
}

这里用到了remove_if(op), 不得不说,这个很好用,意思是list中满足op这个条件的元素将会被全部移除

Problem G: STL——整理唱片(list的使用)的更多相关文章

  1. 实验9:Problem G: 克隆人来了!

    想要输出""的话: cout<<"A person whose name is \""<<name<<" ...

  2. 实验12:Problem G: 强悍的矩阵运算来了

    这个题目主要是乘法运算符的重载,卡了我好久,矩阵的乘法用3个嵌套的for循环进行,要分清楚矩阵的乘法结果是第一个矩阵的行,第二个矩阵的列所组成的矩阵. 重载+,*运算符时,可以在参数列表中传两个矩阵引 ...

  3. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem G: Check The Check(模拟国际象棋)

    Problem G: Check The Check Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 10  Solved: 3[Submit][Statu ...

  4. The Ninth Hunan Collegiate Programming Contest (2013) Problem G

    Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...

  5. 【贪心+中位数】【新生赛3 1007题】 Problem G (K)

    Problem G Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  6. Problem G: If We Were a Child Again

    Problem G: If We Were a Child AgainTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 14[Submi ...

  7. Problem G: Keywords Search

    Problem G: Keywords SearchTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 10 Solved: 6[Submit][Status] ...

  8. Problem I: STL——多重集的插入和删除

    Problem I: STL--多重集的插入和删除 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1729  Solved: 1258[Submit][ ...

  9. BZOJ4977 八月月赛 Problem G 跳伞求生 set 贪心

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4977 - 八月月赛 Problem G 题意 小明组建了一支由n名玩家组成的战队,编号依次为1到n ...

随机推荐

  1. 【环境搭建与软件安装】How to install CUDNN or uninstall

    前言 CuDnn是用于深度学习的GPU加速库,安装好NVIDIA和CUDA之后,安装CuDnn就简单多了,可参考官方文档. 操作过程 1. 下载cuDnn. 需要在NVIDIA官网注册账号,登录之后下 ...

  2. [LeetCode] 207. Course Schedule 课程安排

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  3. 解决GitHub访问速度慢的问题

    https://github.com,但是页面很久才能打开 命令窗口,输入 ping github.com,超时 优化方法: 通过绕过DNS解析,直接在本地绑定host 1.查看ip DNS查看 地址 ...

  4. .Net Core控制台应用程序使用依赖注入、配置文件等

    .Net Core作为一门新语言,资料实在是太少了,并且国内学习的人也不多,虽然性能还行也跨平台了但是生态圈不发展起来也不行 刚出来的时候用 .Net Core + Dapper + Mysql 弄了 ...

  5. [转帖]龙芯3A/3B3000通用处理器出货超30万 获得“中国芯”大奖

    龙芯3A/3B3000通用处理器出货超30万 获得“中国芯”大奖 http://www.eetop.cn/cpu_soc/6946247.html 2019.10 的新闻 出后量 30万 我们贡献了 ...

  6. redhat7.6Linux安装Oracle19C完整版教程

    首先安装配置虚拟机,见博客https://www.cnblogs.com/xuzhaoyang/p/11264563.html 然后配置IP地址,见博客https://www.cnblogs.com/ ...

  7. 阿里P8架构师谈:阿里双11秒杀系统如何设计?

    秒杀是电商业务里的标志性事件,这样的典型高并发场景会遇见什么样的挑战呢,然后又是如何来解决的呢? 秒杀活动场景 淘宝双11秒杀场景,大量的用户短时间内涌入,瞬间流量巨大(高并发),比如:1000万人同 ...

  8. Javascript获取JSON对象长度

  9. python实现查找最长公共子序列

    #!/usr/bin/python # -*- coding: UTF-8 -*- worlds = ['fosh','fort','vista','fish','hish','hello','ohd ...

  10. 【Linux】一步一步学Linux——Bash常用快捷键(11)

    目录 00. 目录 01. 编辑命令 02. 搜索命令 03. 控制命令 04. 其它 05. 参考 00. 目录 @ 生活在 Bash Shell 中,熟记以下快捷键,将极大的提高你的命令行操作效率 ...