Sunday, June 26, 2016

UVA 673 Solution

Unknown
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    while (n--)
    {
        stack<char> check;
        char s[130];
        gets(s);
        int l=strlen(s);
        for (int i=0;i<l;i++)
        {
            if (s[i]=='[' || s[i]=='(')
                check.push(s[i]);
            else if (s[i]==']')
            {
                if (check.empty() || check.top()!='[')
                {
                    check.push('s');
                    break;
                }
                else check.pop();
            }
            else if (s[i]==')')
            {
                if (check.empty() || check.top()!='(')
                {
                    check.push('s');
                    break;
                }
                else check.pop();
            }
        }
        if (check.empty()) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,