20pts 前两个点AC 其他点WA
查看原帖
20pts 前两个点AC 其他点WA
955692
HUNTER_JIN楼主2024/5/31 18:33

用的是stl库里的list

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

list<int> l;
int main(){
	l.push_back(1);
	int n, c, x, y;
	auto it=l.begin();
	cin >> n;
	for(int i=1;i <= n;i++){
		cin >> c;
		if(c == 1){
			cin >> x >> y;
			if(l.back() == x){
			    l.push_back(y);
			    continue;
			}
			for(it=l.begin();it != l.end();it++){
				if(*it == x){
				    it++;
					l.insert(it, y);
				}
			}
		}
		else if(c == 2){
			cin >> x;
			if(l.back() == x){
				cout << "0\n";
				continue;
			}
			for(it=l.begin();it != l.end();it++){
				if(*it == x){
					++it;
					cout << *it << "\n";
					break;
				}
			}
		}
		else{
			cin >> x;
			l.remove(x);
		}
	}
	return 0;
}
2024/5/31 18:33
加载中...