Description
A group of dyed sheep (R, G, and B) are boring, so they started to play games.
The name of the game is queue.
The goat boss said to the younger siblings, "if you want to make a column, I will release a command at any time. My command format is only two:
In x (where X represents one of the color characters R, G, and B, and enters the Team)
Out (Team-out Operation)
There are too many sheep and more cows than the big pineapple.
The boss wants to know the queue status after M operations.
-
Input
-
The first line of the input contains m, n, which indicates that there are m operations and N sheep in the initial queue.
The second line contains n color characters of the initial state goat.
The following M lines provide M commands in the format of question description to ensure that the commands are valid.
Data ensures that no more than 0.1 million sheep are in the same time queue, and the M range is 1 million.
Make sure that any operation is legal.
-
Output
-
Output the queue status after M operations.
The color characters of each sheep in the queue are output from start to end.
-
Sample Input
-
3 2
-
RG
-
IN G
-
OUT
-
OUT
-
Sample output
-
G
Simulation questions, queue
#include <stdio.h>char a[1000000];main(){long m,n;long i,j;char op;long flag1,flag2;scanf("%ld %ld",&m,&n);getchar();for(i=0;i<n;i++){ scanf("%c",&a[i]);}flag2=n;flag1=0;while(m--){getchar();scanf("%c",&op);if(op=='I'){for(i=0;i<2;i++)scanf("%c",&op);scanf("%c",&op); a[flag2]=op; flag2++; }if(op=='O'){for(i=0;i<2;i++)scanf("%c",&op);flag1++;}} for(i=flag1;i<flag2;i++) printf("%c",a[i]);printf("\n");}