AOJ [Aizu-ALDS1_3_C]

原创 2018年04月17日 14:49:47

Your task is to implement a double linked list.

Write a program which performs the following operations:

  • insert x: insert an element with key x into the front of the list.
  • delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.
  • deleteFirst: delete the first element from the list.
  • deleteLast: delete the last element from the list.

Input

The input is given in the following format:

n
command
1 
command2 
...
commandn 

In the first line, the number of operations n is given. In the following n lines, the above mentioned operations are given in the following format:

  • insert x
  • delete x
  • deleteFirst
  • deleteLast

Output

Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.

Constraints

  • The number of operations ≤ 2,000,000
  • The number of delete operations ≤ 20
  • 0 ≤ value of a key ≤ 109
  • The number of elements in the list does not exceed 106
  • For a delete, deleteFirst or deleteLast operation, there is at least one element in the list.

Sample Input 1

7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5

Sample Output 1

6 1 2

Sample Input 2

9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast

Sample Output 2

1



#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
   list <int> L;
   int n;cin>>n;
   while(n--)
   {
        char s[100];int m;
        scanf("%s",s);  //scanf 比cin 效率高!防止超出时间限制 使用scanf
           if(s[0]=='i')
           {
               cin>>m;
               L.push_front(m);
           }else if(s[6]=='F'){
                L.pop_front();
           }else if(s[6]=='L'){
                L.pop_back();
            }else if(s[0]=='d')
            {
                cin>>m;
                for(list <int>::iterator it = L.begin();it!=L.end();it++)
                {
                    if(*it == m)
                    {
                         L.erase(it);
                         break;
                    }
                }
        }
   }
   int i = 0;
   for(list <int>::iterator it = L.begin();it!=L.end();it++)
   {
       if(i++)
        cout<<" ";
       cout<<*it;
   }
   cout<<endl;
   return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Poxiao2017/article/details/79974744

AOJ 0033

链接:点击打开链接 题意:如图所示,十个带有数字的球从上到下依次落下,你可以自由控制挡板D,问是否可以使B,C两管的球都满足球上的数字由下到上依次递增 代码:#include #includ...
  • stay_accept
  • stay_accept
  • 2015-10-28 13:17:22
  • 502

AOJ 0121 Seven Puzzle {广度优先搜索}(*)

原题题意题意是有一个输入,比如:1 0 2 3 4 5 6 7摆成如下形状:1 0 2 3 4 5 6 70表示空格,其他数字可以移动到0的位置。最后需要到如下形状:0 1 2 3 4 5 6 7上面...
  • NoMasp
  • NoMasp
  • 2015-12-13 20:50:44
  • 2310

AOJ 0118

链接:点击打开链接 题意:有三种水果分别用,'@','*','#'三种符号表示,上下左右相连的同种水果被看做是一个区域,问一共有多少个区域 代码:#include #include #incl...
  • stay_accept
  • stay_accept
  • 2015-10-28 12:32:26
  • 539

Aoj 0121 Seven Puzzle【bfs】

题目网址: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0121 http://acm.hust.edu.cn/vjudge/c...
  • liuke19950717
  • liuke19950717
  • 2016-03-05 20:30:06
  • 485

AOJ 0033 Ball (枚举)

题意: 有一个形似央视大楼(233)的筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B裤管或C裤管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B裤管和C裤管中...
  • synapse7
  • synapse7
  • 2013-11-07 17:52:05
  • 1804

会津大学在线测评 AOJ Aizu Online Judge http://judge.u-aizu.ac.jp 注册 登录

会津大学在线测评 AOJ Aizu Online Judge http://judge.u-aizu.ac.jp 注册 登录 无法注册,无法登陆,怎么办,抓狂啊。 直接导致《挑战程序设计竞赛 算法和数...
  • mrcrack
  • mrcrack
  • 2017-09-20 09:06:33
  • 736

AOJ 0118 Property Distribution 题解

题意大概就是判断区域的个数,同样的字符属于一个区域,问有多少个区域. 想起来以前一位老师给我讲的一道类似的题目...直接DFS求解,已经判断过的区域再用另一个字符填上即可. #include #i...
  • lrb2010
  • lrb2010
  • 2014-01-16 13:53:15
  • 795

AOJ 569 快速幂

乘的更快 Time Limit: 1000 ms   Memory Limit: 64 MB Total Submission: 837   Submission Accepted: 145 ...
  • u013748887
  • u013748887
  • 2014-03-13 00:01:25
  • 507

Seven Puzzle (AOJ 0121 bfs)

题意:给出0~7的序列(2*4),只能0和周围数字交换,问最少交换多少次可以是给出的序列变成0 1 2 3 4 5 6 7 思路:先搜一遍把所有答案保存下来。大哭因为一句话位置写错了当时没做出来。。...
  • u014422052
  • u014422052
  • 2015-03-22 22:51:26
  • 819

AOJ 0121:Seven Puzzle(bfs)

原文地址:点击打开链接 题意: 7数码问题。在2×4的棋盘上,摆有7个棋子,每个棋子上标有1至7的某一数字,不同棋子上标的数字不相同。棋盘上还有一个空格(用0表示),与空格相邻(上下左右)的棋子可以移...
  • luoluozlb
  • luoluozlb
  • 2016-05-07 11:06:44
  • 572
收藏助手
不良信息举报
您举报文章:AOJ [Aizu-ALDS1_3_C]
举报原因:
原因补充:

(最多只允许输入30个字)