#21180: C++ AC


slime.creeper3@gmail.com (Slimlix)

學校 : 不指定學校
編號 : 108310
來源 : [114.27.68.205]
最後登入時間 :
2021-09-07 22:44:18
e447. queue 練習 | From: [114.27.17.3] | 發表日期 : 2020-04-26 12:02

用Vector

 

 

 

#include <iostream>

#include <vector>

using namespace std;

int main()

{

     int n, input, x, i = 0;

     vector<int> queue;

     while (cin >> n)

     {

          do

          {

               cin >> input;

               switch (input)

               {

                    case 1: // Add element after the queue

                         cin >> x;

                         queue.push_back(x);

                         break;

                    case 2: // Output the first element

                         if (queue.empty()) cout << -1 << endl;

                         else cout << queue[0] << endl;

                         break;

                    case 3: // Remove the first element

                         if (!queue.empty()) // If queue ISN'T empty, remove the first element

                         {

                              queue.pop_back();

                              for (int w = 0 ; w < queue.size() ; w++)

                                   queue[w] = queue[w+1];

                         }

                         break;

               }

               i++; 

          } while (i < n);   

     }   

     return 0;

 }

 

 
ZeroJudge Forum