标签:des style blog io ar os for sp strong
sin(20+10)
{[}]
yes no
注意:读入的字符串里可能含有空格哦!
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <map>
#include <stack>
#include <deque> //双端队列
#include <queue>
#include <algorithm>
#include <ctype.h>
using namespace std;
int main()
{
char s[100];
int i, j;
while(gets(s)!=NULL)
{
unsigned int len=strlen(s);
stack<char>q;
for(i=0; i<len; i++)
{
if(s[i]==‘(‘ || s[i]==‘[‘ ||s[i]==‘{‘)
{
q.push(s[i]);
}
else if(s[i]==‘)‘)
{
if(q.empty() || q.top()!=‘(‘)
{
q.push(s[i]);
}
else if(q.top()==‘(‘)
{
q.pop();
}
}
else if(s[i]==‘]‘)
{
if(q.empty() || q.top()!=‘[‘)
{
q.push(s[i]);
}
else if(q.top()==‘[‘)
{
q.pop();
}
}
else if(s[i]==‘}‘)
{
if(q.empty() || q.top()!=‘{‘)
{
q.push(s[i]);
}
else if(q.top()==‘{‘)
{
q.pop();
}
}
}
if(q.empty())
printf("yes\n");
else
printf("no\n");
}
return 0;
}
标签:des style blog io ar os for sp strong
原文地址:http://www.cnblogs.com/yspworld/p/4079848.html