标签:lib get eof ace mes stream nbsp getc iostream
南阳理工学院oj题解
//括号匹配问题
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
using namespace std;
int main()
{
int k, flag = 1;
char c,*q;
char s[10010];
scanf("%d",&k);
getchar();
for (int i = 0; i < k; i++)
{
stack<char>a;
flag = 1;
int j = 0;
while (scanf("%c", &c)!=EOF&&c!=‘\n‘)
{
s[j++] = c;
}
for (int i = 0; i < j; i++)
{
if (s[i] == ‘(‘ || s[i] == ‘[‘)
{
a.push(s[i]);
}
else if (s[i] == ‘)‘ || s[i] == ‘]‘)
{
if (a.empty())
{
flag = 0;
break;
}
if (s[i] == ‘)‘&&a.top() == ‘(‘)
a.pop();
else if (s[i] == ‘]‘&&a.top() == ‘[‘)
a.pop();
else
{
flag = 0;
break;
}
}
}
if (flag == 1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
标签:lib get eof ace mes stream nbsp getc iostream
原文地址:http://www.cnblogs.com/marybubble/p/7898326.html