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] 250. Count Univalue Subtrees 计算唯一值子树的个数
Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of ...
- [LeetCode] 324. Wiggle Sort II 摆动排序 II
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]... ...
- 阿里云k8s构建镜像时设置版本号用于版本回滚
jenkins 构建配置参数化构建过程 构建 执行 shell , 将版本号参数传入 脚本 脚本push 带版本号的镜像到阿里云镜像仓库 #!/bin/bash #获取参数 while geto ...
- python测试工具nosetests
今天在github上找东西,找到个工具是python写的,但是需要安装nosetests,因此了解了下nosetests python除了unittest,还有nosetests,使用更快捷 nose ...
- 【神经网络与深度学习】Win10+VS2015 caffe环境搭建(极其详细)
caffe是好用,可是配置其环境实在是太痛苦了,依赖的库很多不说,在VS上编译还各种报错,你能想象那种被一百多个红色提示所笼罩的恐惧. 且网上很多教程是VS2013环境下编译的,问人很多也说让我把1 ...
- grok语法定义
grok默认表达式 Logstash 内置了120种默认表达式,可以查看patterns,里面对表达式做了分组,每个文件为一组,文件内部有对应的表达式模式.下面只是部分常用的. 常用表达式 表达式标识 ...
- 引用js文件中的函数调用
开发中遇到一个问题,代码demo如下: test.js文件内容: var b = getHomeCity(); Test.html文件内容: <!DOCTYPE html> <htm ...
- 解决python中的Non-UTF-8 code starting with ‘\xbs4’ in file错误
出现错误如下图: 主要原因为编辑python脚本使用的编辑器编码有问题.我使用的编辑器是notepad++,由于没有做Python语言编辑配置,默认使用的是ANSI编码(右下角位置有编码格式),如下: ...
- Modelsim——do脚本、bat命令
一.do脚本实现自动化仿真 Modelsim是支持命令的,我们可以用 .do 文件将这些命令先写好然后在Modelsim上调用.因为我的编辑器不支持.do的语法,所以这里改用 .tcl文件,它和 .d ...
- TweenMax参数用法中文介绍
TweenMax 建立在 TweenLite 和 TweenFilterLite 基础之上,因此,又揉合了这二者的功能,使得功能更加的齐备,但是如果说易用性,觉得还是 TweenLite 来得方便一些 ...