第一行一个正整数n, (1<=n<=100000),表示操作的个数
接下来n行,每行有一个操作,
如果操作为push,则后面接一个正整数v(1<=v<=100000)表示push进队列的数;
如果操作为pop,则应输出pop出的数为多少。
对于每个pop操作,输出pop出的数为多少。
10 push 60 pop push 9 pop push 27 pop push 22 push 37 pop push 100
60 9 27 22
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] fifo = new int[100001];
int start = 0;
int end = 0;
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
String s = scanner.next();
if (s.equals("push")) {
int p = scanner.nextInt();
fifo[end++] = p;
} else if (s.equals("pop")) {
System.out.println(fifo[start++]);
}
}
scanner.close();
}
}
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main()
{
int n = 0;
while(cin >> n)
{
// 用vetor模拟实现就可以
vector<int> fifo;
while(n--)
{
string s1;
cin >> s1;
if(s1 == "push")
{
int val = 0;
cin >> val;
fifo.push_back(val);
}
else
{
int val = fifo.front();
fifo.erase(fifo.begin());
cout << val << endl;
}
}
}
return 0;
}