View Code of Problem 3913

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main(void)
{
    int n;
    cin >> n;
    getchar();
    string str;
    while(n--){
        int flag = 1;
        stack<char> sc;
        cin >> str;
        for (int i = 0; i < str.size() && flag;i++){
            if(str[i] == '(')
                sc.push(str[i]);
            else{
                if(!sc.empty()){
                    sc.pop();
                }else{
                    flag = 0;
                }
            }
        }
        if(!sc.empty())
            flag = 0;
        cout << (flag == 1 ? "Yes" : "No") << endl;
    }
}

Double click to view unformatted code.


Back to problem 3913