zoukankan      html  css  js  c++  java
  • 序列3

    【题目描述】
    你有一个序列,一开始它是空的,现在有三种操作:

    1. 将一个数a加入序列,放在第k个位置,其余的数依次后移
    2. 将第k个位置上的数删除,后面的数向前移
    3. 查询第k个位置上的数,如果不存在第k个位置,输出Wrong Places
      注意:当没有元素时,插入默认在第一个位置,一共有n个操作
      【输入格式】
      第一行 n
      剩下的n行:
      1.有一个1和两个数a,k,表示操作1
      2.有一个2和k,表示操作2
      3.有一个3和k,表示操作3
      【输出格式】
      对于每个操作3,输出一行表示答案
      【输入样例】
      7
      1 10 1
      1 3 1
      3 1
      2 1
      3 1
      2 1
      3 1
      【输出样例】
      3
      10
      Wrong Places
      【数据范围】
      0%的数据 n<=0
      50%的数据 n<=100
      100%的数据n<=10000
    #include<bits/stdc++.h>
    using namespace std;
    int a[10000001];
    int main(){
    	freopen("last.in", "r", stdin);
    	freopen("last.out", "w", stdout);
    	int n, l = 0;
    	cin >> n;
    	memset(a, -1, sizeof(a));
    	for(int i = 1; i <= n; i++){
    		int x;
    		scanf("%d", &x);
    		if(x == 1){
    			int b, c;
    			scanf("%d%d", &b, &c);
    			if(l == 0){
    				l++;
    				a[l] = b;
    			}else{
    				if(c > l){
    					l = c;
    					a[l] = b;
    				}
    				else{
    					if(a[l] == -1)a[l] = b;
    					else{
    						l++;
    						for(int j = l; j >= c+1; j--)a[j] = a[j-1];
    						a[c] = b;
    					}
    				}
    			}
    		}
    		else if(x == 2){
    			l--;
    			if(l == 0)memset(a, -1, sizeof(a));
    			int b;
    			scanf("%d", &b);
    			for(int j = b; j <= l; j++)a[j] = a[j+1];
    		}
    		else{
    			int b;
    			scanf("%d", &b);
    			if(a[b] == -1)printf("Wrong Places
    ");
    			else printf("%d
    ", a[b]);
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    netty中Pipeline的ChannelHandler执行顺序案例详解
    Pi-设置无线
    Pi1-Centos
    gitlab升级
    ansible
    我也玩Jenkins
  • 原文地址:https://www.cnblogs.com/LJA001162/p/13392040.html
Copyright © 2011-2022 走看看