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 ...
随机推荐
- byte类型的取值为什么是-128~127
参考:https://blog.csdn.net/qq_22771739/article/details/84496115 https://blog.csdn.net/boatalways/artic ...
- js:如何获取select选中的值
我想获取select选中的value,或者text,或者…… 比如这个: <select id="select"> <option value=" ...
- robot:当用例失败时执行关键字(发送短信)
使用场景: 当用例失败时需要通知对应人员,则需要在Teardown中,使用关键字Run Keyword If Test Failed Send Message关键字为自定义关键字,${content} ...
- SpringBoot+Mybatis+MySql 自动生成代码 自动分页
一.配置文件 <!-- 通用mapper --> <dependency> <groupId>tk.mybatis</groupId> <arti ...
- TCP/IP学习笔记5--网络的构成要素
人的灵魂来自一个完美的家园,那里没有任何污秽和丑陋,只有纯净和美丽.----大鱼海棠 1.通信媒介与数据链路 计算机之间通过各种电缆相互连接. 2.网卡 任何一台计算机接入网络都需要网卡,又称网络适配 ...
- vue中$router以及$route的使用
路由基本概念 route,它是一条路由. { path: '/home', component: Home } routes,是一组路由. const routes = [ { path: '/hom ...
- SpringMVC笔记1
SpringMVC是一个一种基于Java的实现MVC设计模型的请求驱动类型的轻量级web框架 SpringMVC的入门案例 2.导入相关jar包 <?xml version="1.0& ...
- Django REST Framework批量更新rest_framework_extensions
Django REST framework 是一套基于Django框架编写RESTful风格API的组件. 其中mixins配合viewsets能极其方便简化对数据的增删改查, 但本身并没有对数据的批 ...
- day29——socket套接字(少量不全)
day29 socket套接字 socket是处于应用层与传输层之间的抽象层,他是一组操作起来非常简单的接口(接受数据)此接口接受数据之后,交由操作系统. 为什么存在socket抽象层? 如果直接与操 ...
- module 'pip._internal' has no attribute 'pep425tags'
一.问题分析 这是python 3.x不能用2.x的版本问题 二.解决方案 import wheel.pep425tags as w print(w.get_supported()) 输出: [('c ...