HDU1870

来源:互联网 发布:淘宝详情页怎么优化 编辑:程序博客网 时间:2024/05/22 17:19

栈的基础水题 看懂题意就会写了,是(入栈是)出一个,表示抵销,不会拆这个礼物。

#include<iostream>#include<stack>#include<cstring>using namespace std;int main(){    char a[1001];    stack<int> s;    while(cin>>a)    {        int l=strlen(a);        for(int i=0;i<l;i++)        {            if(a[i]=='(')                s.push(1);            else if(a[i]==')')                s.pop();            else                break;        }        int i=0;        while(!s.empty())        {          s.pop();          i++;        }        cout<<i<<endl;    }    return 0;}
0 0
原创粉丝点击