zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    9-1058. 选择题(20)
    8-素数打表
    7- 插入与归并
    6-爱丁顿数(题意理解)
    5-单身狗(时间和空间的相互选择)
    4-1068. 万绿丛中一点红
    3-1067. 试密码
    2-素数打比表
    21-矩形的嵌套
    maven设置打jar包并引入依赖包
  • 原文地址:https://www.cnblogs.com/AlphaWA/p/10952129.html
Copyright © 2011-2022 走看看