1365 dyeing sheep

Source: Internet
Author: User
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");}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.