ZOJ Problem Set - 4016(list容器的用法)

传送门

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<list>
using namespace std;
const int maxn=3e5+10;
typedef long long ll;
list<int> l[maxn];

int main(){
	int T, n, q;
	scanf("%d", &T);
	
	while(T--){
		scanf("%d%d", &n, &q);
		for(int i=1; i<=n; i++)
			l[i].clear();
		int op;
		while(q--){
			scanf("%d", &op);
			if(op==1)
			{
				int s, v;
				scanf("%d%d", &s, &v);
				l[s].push_back(v);
			}
			else if(op==2)
			{
				int s;
				scanf("%d", &s);
				if(l[s].empty())
					printf("EMPTY\n");
				else
				{
					printf("%d\n", l[s].back());
					l[s].pop_back();
				}	
			}
			else
			{
				int s, t;
				scanf("%d%d", &s, &t);
				l[s].splice(l[s].end(), l[t]);
			}
			
		}
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/du_lun/article/details/79852150