40分求助
  • 板块P9518 queue
  • 楼主Yves0709
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/8/17 15:54
  • 上次更新2023/11/3 03:08:02
查看原帖
40分求助
668684
Yves0709楼主2023/8/17 15:54
#include <bits/stdc++.h>
using namespace std;
list<string> a;
map<string, bool> m;
char c[10];
string now1 = "0", now2 = "0", t;
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		memset(c, 0, sizeof(c)); cin >> c;
		if (c[0] == 's')
		{
			if (now1 != "0") a.push_back(now1);
			if (now2 != "0") a.push_back(now2);
			
			if (!a.size()) cout << "Error\n";
			else if (a.size() == 1) 
			{
				while (!m.count(a.front())) a.pop_front();
				now1 = a.front(); cout << now1 << "\n"; 
				a.pop_front(); now2 = '0';
			}
			else
			{
				while (!m.count(a.front())) a.pop_front();
				now1 = a.front(); cout << a.front() << " "; 
				a.pop_front();
				while (!m.count(a.front())) a.pop_front();
				now2 = a.front(); cout << a.front() << "\n"; 
				a.pop_front();
			}
		}
		else if (c[0] == 'a')
		{
			cin >> t; 
			if (m.count(t)) {cout << "Error\n"; continue;}
			else {m[t] = 1; a.push_back(t); cout << "OK\n";}
		}
		else if (c[0] == 'l')
		{
			cin >> t;
			if (now1 == t || now2 == t || !m.count(t)) {cout << "Error\n"; continue;}
			else {cout << "OK\n"; m.erase(t);}
		}
	} 
	return 0;
}

2023/8/17 15:54
加载中...