1 条题解
-
0
画出表达式树,不难发现答案就是树上同种操作构成的极大连通块个数。
#include <bits/stdc++.h> using namespace std; int main() { freopen("compounds.in", "r", stdin); freopen("compounds.out", "w", stdout); int T; cin >> T; while (T--) { string S; cin >> S; int ans = 0; stack <int> st; st.push('#'); for (int i = 0; i < S.size(); i++) { if (S[i] == '(' && st.top() != S[i - 1]) ans++; if (S[i] == '(') st.push(S[i - 1]); if (S[i] == ')') st.pop(); } cout << ans << endl; } return 0; }
- 1
信息
- ID
- 231
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 4
- 标签
- 递交数
- 47
- 已通过
- 10
- 上传者