题目:点击打开链接
今个儿携程要是这么简单就好了。。
不是‘(’就是‘)’,如果出现了B,那么清空栈,最后+1取相反数。其实根本用不着存进去- -。。直接假装有个栈就行。。
The reason I wrote it is I feel traumatized by the competition......TAT
#include <iostream>
using namespace std;
int main()
{
char str[1001];
int top, i, j;
while(cin >> str){
top = -1;
for(i = 0; str[i] != ‘\0‘; i++){
char &ch = str[i];
if(ch == ‘(‘)
top++;
else if(ch == ‘)‘)
top--;
else
top = -1;
}//end i
cout << -(top + 1) <<endl;
}//end str
return 0;
}
原文:http://blog.csdn.net/svitter/article/details/23388951