Codeforces 190C(模拟)

坑点

  • 不记它难解我心头之恨……
  • WA1:不要读错题Orz,顺序是按它给定的。那就是个类似栈的东西,重点在于输出。
  • 然而我输出很快就模拟对了……
  • WA2:数据:1 int。我日了不看数据我真的去de模拟的bug了。
  • WA3:中间栈空是非法。
  • 貌似建一棵树可以迅速搞掉……擦
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int maxn = 1e5 + 5;
int n, m, cnt, flag, mark[maxn], go, last[maxn];
string s;
vector<string> v;
int p[maxn][2], x = 1;

void print(int now) {
	cout << "pair<";
	if (p[now][0] > 0)	print(p[now][0]);
	else	cout << "int";
	cout << ",";
	if (p[now][1] > 0)	print(p[now][1]);
	else	cout << "int";
	cout << ">";	
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	while (cin >> s) {
		if (s == "pair") {
			if (!m) {
				go = ++m;
				mark[go] = 0;
				cnt += 2;
				continue;
			}
			if (cnt == 0)	flag = 1;
			cnt++;
			p[go][mark[go]] = ++m;//pair
			mark[go] ^= 1;
			last[m] = go;
			go = m;
		} else {
			if (cnt == 0)	flag = 1;
			cnt--;
			p[go][mark[go]] = -1;//int
			mark[go] ^= 1;
			while (go && mark[go] == 0)	go = last[go];
		}
	}
	if (m == 0 && n == 1) {//淦
		cout << "int"; return 0;
	}
	if (cnt || flag) {
		cout << "Error occurred";
	} else {
		print(x);
	}
}
// pair pair int pair int int pair int int
posted @ 2019-05-30 21:22  AlphaWA  阅读(198)  评论(0编辑  收藏  举报