Jane Queue--line up to buy food

Source: Internet
Author: User

The experiment of queue data structure: line up to buy food

Time limit:1000ms Memory limit:65536k Topic Description Narration

There are many people who buy rice at noon, canteen is really too crowded, buy a meal laborious, science and technology big Child is very clever, straight to the political pass supermarket, haha, indeed, political pass supermarket inside also sells rice, there are several vegetables, do more than canteen delicious, price is not more expensive than canteen, and buy vegetables to send soy milk, attracted a lot of children's shoes. So sometimes, people are still very many, the queue is unavoidable, tragedy is the supermarket has only two cashier form.

The problem is this: Two teams are queuing up and now we're just studying the first team. Now we give each person a number. The guarantee number is not the same. The people in front of them buy the meal and leave, and some people pick up the meal and wait in the back for payment. There are some people who are smarter and see that there is less of a team, just leave the team and have a team.

I'm asking about the total number of teams and the number of people in a certain location.



Input

First enter an integer m (m<10000). The representative currently has m individuals, the second line enters the number of M, and represents the number of each person. The third line enters an integer n (n<10000), which represents the queue change and asks altogether n times, after n rows. The JOIN x represents the number of people who are numbered X (which is guaranteed to be different from the previous number), and LEAVE y indicates that the person in the position of Y (Y is less than the current queue length) is dropped; ask Z (Z is less than the current queue length) indicates the number of the person asking for the z position. Finish d indicates that the D-person has left the meal after buying; Length indicates how long the queue is queried.

Ensure that all data is within the INT range.

Output

Answer for each query output. Each answer takes up one line.

Demo sample Input
3
1 2 3
6
JOIN 4
ASK 2
LEAVE 2
LENGTH
FINISH 2
LENGTH
Demo sample Output
2
3
1

Think of the whole team as a queue. When someone leaves, the people behind them move forward.

The code is as follows:

#include <stdio.h> #include <string.h> int main () {int n,m,i,k,a[11000];      Char s[10];      scanf ("%d", &m);    for (i=1;i<=m;i++) scanf ("%d", &a[i]);      /*m always indicates the length of the team */scanf ("%d", &n);          while (n--) {scanf ("%s", s);              if (strcmp (S, "JOIN") ==0) {scanf ("%d", &a[i++]);          m++;              } else if (strcmp (S, "LEAVE") ==0) {scanf ("%d", &k);              for (i=k;i<m;i++)/* Someone has left the team again, the front is not moving, just need to move forward in the back * * a[i]=a[i+1];          m--;              } else if (strcmp (S, "ASK") ==0) {scanf ("%d", &k);          printf ("%d\n", A[k]);              } else if (strcmp (S, "FINISH") ==0) {scanf ("%d", &k);              For (i=1;i<= (m-k); i++)//* Same, here again row */a[i]=a[i+k];          M=m-k; } else if (strcmp (S, "LENGTH") ==0) printf ("%d\n", m);  } return 0;   }


Jane Queue--line up to buy food

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.