Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

struct stack
{
    
int n[1001], top;
    stack()
    {
        memset(n, 
0sizeof n);
        top 
= 0;
    }
    
int pop()
    {
        
if(top > 0)
            
return n[top--];
        
return 0;
    }
    
void push(int x)
    {
        n[
++top] = x;
    }
    
bool empty();
}stk;

bool stack::empty()
{
    
if(top == 0)
        
return true;
    
return false;
}

int main()
{
    
bool flag = false;
    
string str;
    cin 
>> str;

    
for(int i = 0; str[i] != '@'; i++)
    {
        
if(str[i] == '(')
        {
            stk.push(
1);
            flag 
= true;
        }
        
if(str[i] == ')')
        {
            flag 
= true;
            
if(stk.empty())
                stk.push(
2);
            
if(stk.n[stk.top] == 1)
                stk.pop();
        }
    }

    
if(flag == false)
        cout 
<< "YES" << endl;
    
if(flag == true)
        
if(stk.empty())
            cout 
<< "YES" << endl;
        
else
            cout 
<< "NO" << endl;

    
return 0;
}

posted on 2009-09-15 21:26 mad4alcohol 阅读(156) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理