-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday65.cpp
More file actions
38 lines (33 loc) · 859 Bytes
/
day65.cpp
File metadata and controls
38 lines (33 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
bool hasRedundantVines(const string &s) {
stack<char> st;
for (char ch : s) {
if (ch == ')') {
char top = st.top();
st.pop();
bool hasOperator = false;
while (!st.empty() && top != '(') {
if (top == '+' || top == '-' || top == '*' || top == '/') {
hasOperator = true;
}
top = st.top();
st.pop();
}
if (!hasOperator) return true; // Redundant pair found
} else {
st.push(ch);
}
}
return false;
}
int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
cout << (hasRedundantVines(s) ? "true" : "false") << endl;
}
return 0;
}