求助大佬QAQ,蒟蒻只能过4个点

P1241 括号序列

代码改成这样后有6个点超时,大佬帮帮QAQ ``` #include<iostream> #include<iomanip> #include<math.h> #include<algorithm> #include<cstdio> #include<cstring> #include<string> #include<queue> #include<vector> #include<stack> #define maxn 1000010 using namespace std; queue<char> q; struct node { char s; bool pan; }z[maxn]; int sum, point = 0; int main() { char a; while (cin >> a) { q.push(a); } while (q.size() > 0) { char one = q.front(); if (one == '(') { z[point].s = one; z[point].pan = false; point++; q.pop(); } else if (one == ')') { for (int i = point - 1; i >= 0; --i) { if (z[i].s == '('&&z[i].pan==false) { if (z[i].pan == false) { z[i].pan = true; z[point].s = one; z[point].pan = true; point++; q.pop(); break; } else if (z[i].pan == true) { z[point].s = one; z[point].pan = false; point++; q.pop(); break; } } else if (z[i].s == '['&&z[i].pan==false) { z[point].s = one; z[point].pan = false; point++; q.pop(); break; } } } else if (one == ']') { for (int i = point - 1; i >= 0; --i) { if (z[i].s == '[' && z[i].pan == false) { if (z[i].pan == false) { z[i].pan = true; z[point].s = one; z[point].pan = true; point++; q.pop(); break; } else if (z[i].pan == true) { z[point].s = one; z[point].pan = false; point++; q.pop(); break; } } else if (z[i].s == '(' && z[i].pan == false) { z[point].s = one; z[point].pan = false; point++; q.pop(); break; } } } else if (one == '[') { z[point].s = one; z[point].pan = false; point++; q.pop(); } //cout << z[point-1].s << " " << z[point-1].pan << endl; } for (int i = 0; i < point; ++i) { if (z[i].pan) { cout << z[i].s; } else { if (z[i].s == '(' || z[i].s == ')') { cout << "()"; } else if (z[i].s == '[' || z[i].s == ']') { cout << "[]"; } } } return 0; } ```
by jiunichenyin @ 2024-03-24 10:36:07


|