Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int n; cin >> n;
- string z;
- getline(cin,z);
- for(int j = 0; j < n; j++){
- getline(cin,z);
- bool ok = true;
- deque<int> deq;
- for(int i = 0; i < z.size();i++){
- if(z[i]=='('||z[i]=='['||z[i]=='{'){
- if(i!=0&&z[i-1]==':'){
- //cout << "lol";
- continue;
- }
- deq.push_back(z[i]);
- }
- else if(z[i]==')'||z[i]==']'||z[i]=='}'){
- if(i!=0&&z[i-1]==':'){
- //cout << "lol";
- continue;
- }
- if(deq.empty()){
- cout << 1 << "\n";
- ok = false;
- break;
- }
- else{
- int x = deq.back();
- // cout << x << " " << z[i];
- int cnt = 0;
- if(z[i]==')'){
- cnt = 1;
- }else{
- cnt = 2;
- }
- if(z[i]==x+cnt){
- deq.pop_back();
- continue;
- }else{
- cout << 2 <<"\n";
- ok = false;
- break;
- }
- }
- }
- }
- if(ok&&!deq.empty()){
- cout << 3 <<"\n";
- }
- else if(ok&&deq.empty()){
- cout << 0 << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement