8 solutions

  • 0
    @ 2022-1-14 15:09:50
    #include<queue>
    #include<deque>
    #include<iostream>
    #include<string.h>
    using namespace std;
    
    int main()
    {
    	int n,a;
    	scanf("%d",&n);
    	char arr[10];
    	deque<int>que;
    	int num[10007];
    	for(int i = 1; i <= n; i++)
    	{
    		scanf("%s",arr);
    		if(strcmp(arr,"LIN") == 0)
    		{
    		scanf("%d",&a);
    		que.push_front(a);	
    		}
    		else if(strcmp(arr,"RIN") == 0)
    		{
    			scanf("%d",&a);
    			que.push_back(a);
    		}
    		else if(strcmp(arr,"ROUT") == 0)
    		{
    			if(!que.empty())
    			{
    				que.pop_back();
    			}
    			else
    			{
    				num[i]++;
    			}
    		}
    		else if(strcmp(arr,"LOUT") == 0)
    		{
    			if(!que.empty())
    			{
    				que.pop_front();
    			}
    			else
    			{
    				num[i]++;
    			}
    		}
    		
    	}
    	while(!que.empty())
    	{
    		printf("%d ",que.front());
    		que.pop_front();
    	}
    	puts("");
    	for(int i = 1;i <= n;i ++)
    	{
    		if(num[i] == 1)
    		{
    			printf("%d ERROR\n",i);
    		}
    	}
    	return 0;
    }
    
    

    Information

    ID
    1125
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    6
    Tags
    # Submissions
    136
    Accepted
    43
    Uploaded By