Blue Bridge Cup Algorithm Improvement - Queue Operation

Problem Description
  Queue operation problem. According to the input operation command, the operation queue (1) is enqueued, (2) is dequeued and output, and (3) the number of elements in the queue is calculated and output.
Input format One number N in the
  first line.
  The following N lines, the first number of each line is the operation command (1) to enter the queue, (2) to dequeue and output, (3) to calculate the number of elements in the queue and output.
Output Format
  Several lines each show the output of a 2 or 3 command. Note: 2. The dequeue command may appear empty queue (underflow), please output "no" and exit.
Sample input
7
1 19
1 56
2
3
2
3
2
Sample output
19
1
56
0
no
data size and convention
  1<=N<=50

#include<iostream>
#include<queue>
using namespace std;

int main()
{
    int N,op,num;
    queue<int>s;
    cin >> N;
    while(N)
    {
        cin >> op;
        N--;
        if(op == 1)
        {
            cin >> num;
            s.push(num);
        }
        else if(op == 2)
        {
            if(s.empty()) {cout << "no" << endl;break;}

            cout << s.front() << endl;
            s.pop();
        }
        else if(op == 3){cout << s.size() << endl;}
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325806304&siteId=291194637