#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. [LeetCode] 407. Trapping Rain Water II 收集雨水 II

    Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...

  2. app内嵌h5页面在ios手机端滑动卡顿的解决方法

    1.带滚动条的dom需加样式 -webkit-overflow-scrolling: touch;2.去掉 width:100%; height:100%

  3. Django ORM 数据库设置和读写分离

    一 Django的数据库配置 (一)修改settings.py文件关于数据库的配置: Django默认使用sqlite: DATABASES = { 'default': { 'ENGINE': 'd ...

  4. EditPlus配置ftp连接linux

    选择文件/FTP下面的设置FTP服务器 1.点击添加 2.填写名称.ftp服务器.用户名.密码信息 3.点击高级设置 4.选择加密方式为sftp,端口22,如果不填端口号,默认也是22,确定 5.确定 ...

  5. Prometheus入门到放弃(4)之cadvisor监控docker容器

    Prometheus监控docker容器运行状态,我们用到cadvisor服务,cadvisor我们这里也采用docker方式直接运行. 1.下载镜像 [root@prometheus-server ...

  6. C++的派生类构造函数是否要带上基类构造函数

    //public:Student(int s_age):People(s_age) //C++的派生类构造函数后面是否带上基类构造函数,取决于基类构造函数是否需要传入参数,如果要参数,就一定带上:不需 ...

  7. Django最全思维导图

    思维导图传送门

  8. centos6.5升级openssh至7.9p1

    环境说明系统环境:centos 6.5 x64 openssh-5.3p1升级原因:低版本openssh存在漏洞升级目标:openssh-7.9p1 检查环境官方文档中提到的先决条件openssh安装 ...

  9. tkinter学习笔记_03

    6.单选框   Radiobutton import tkinter as tk root = tk.Tk() root.title("xxx") root.geometry('2 ...

  10. [LOJ2292] [THUSC2016] 成绩单

    题目链接 LOJ:https://loj.ac/problem/2292 洛谷:https://www.luogu.org/problemnew/show/P5336 Solution 区间\(\rm ...