Problem G: STL——整理唱片(list的使用)
#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的使用)的更多相关文章
- 实验9:Problem G: 克隆人来了!
想要输出""的话: cout<<"A person whose name is \""<<name<<" ...
- 实验12:Problem G: 强悍的矩阵运算来了
这个题目主要是乘法运算符的重载,卡了我好久,矩阵的乘法用3个嵌套的for循环进行,要分清楚矩阵的乘法结果是第一个矩阵的行,第二个矩阵的列所组成的矩阵. 重载+,*运算符时,可以在参数列表中传两个矩阵引 ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem G: Check The Check(模拟国际象棋)
Problem G: Check The Check Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 10 Solved: 3[Submit][Statu ...
- 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 ...
- 【贪心+中位数】【新生赛3 1007题】 Problem G (K)
Problem G Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- 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 ...
- Problem G: Keywords Search
Problem G: Keywords SearchTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 10 Solved: 6[Submit][Status] ...
- Problem I: STL——多重集的插入和删除
Problem I: STL--多重集的插入和删除 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1729 Solved: 1258[Submit][ ...
- BZOJ4977 八月月赛 Problem G 跳伞求生 set 贪心
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4977 - 八月月赛 Problem G 题意 小明组建了一支由n名玩家组成的战队,编号依次为1到n ...
随机推荐
- [LeetCode] 297. Serialize and Deserialize Binary Tree 二叉树的序列化和反序列化
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- java里的static/final含义
java里的static/final含义 static static可以修饰:属性,方法,代码段,内部类(静态内部类或嵌套内部类) static修饰的属性的初始化在编译期(类加载的时候),初始化后能改 ...
- 【视频版】PDF合并器破解视频教程
无聊顺手录了一下,需要的拿去. 下载地址: 链接:https://pan.baidu.com/s/1TtK1JNzNw0BIl0eRPS_nlw 提取码复制可见:pqgi
- 密钥密码体系CA,CSC,CV
密钥密码体系CA,CD,CSC,CV 片内操作系统 (cos) 密码学(Cryptography) 非接触式智能卡Contactless Smart Card, CSC 密钥名词 名词 英文说明 中文 ...
- Postgresql中的large object
1.初识postgresql large object 一位同事在对使用pg_dump备份出来的文件(使用plain格式)进行恢复时,觉得速度非常慢,让我分析一下是什么原因. 我拿到他的.bak文件, ...
- Django文档阅读之模型
模型 模型是您的数据唯一而且准确的信息来源.它包含您正在储存的数据的重要字段和行为.一般来说,每一个模型都映射一个数据库表. 基础: 每个模型都是一个 Python 的类,这些类继承 django.d ...
- 2019暑假牛客多校训练-第八场-C-CDMA(递归、水题)
观察前3组可以推出递归规律,生成下一个类型时,每行copy自身与自身相反. 题目描述 Gromah and LZR have entered the third level. There is a b ...
- TCP/IP学习笔记12-- IP协议基础
IP(internet protocol, 网际协议) IP相当于OSI参考模型中的第三层 -- 网络层. --网络层的下一层--数据链路层的主要作用是在 同一种数据链路 的节点之间进行包传递,而一旦 ...
- docker使用1
1. 安装 可以参考https://www.runoob.com/docker/centos-docker-install.html 注意linux版本是centos7.6 2. docker启动,停 ...
- 09 Servlet相关知识点---学习笔记
1.概念:运行在服务器端的小程序 Servlet就是一个接口,定义了Java类被浏览器访问到(tomcat识别)的规则.将来我们自定义一个类,实现Servlet接口,复写方法. 2.快速入门:(1)创 ...