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

转载于:https://www.cnblogs.com/AlphaWA/p/10952129.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值