题目:
| 愚人节的礼物 | 
| Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) | 
| Total Submission(s): 49 Accepted Submission(s): 44 | 
|   | 
| Problem Description      四月一日快到了,Vayko想了个愚人的好办法——送礼物。嘿嘿,不要想的太好,这礼物可没那么简单,Vayko为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物。盒子里面可以再放零个或者多个盒子。假设放礼物的盒子里不再放其他盒子。      
 | 
| Input      本题目包含多组测试,请处理到文件结束。      
 | 
| Output 对于每组测试,请在一行里面输出愚人指数。 
 | 
| Sample Input ((((B)()))())(B) 
 | 
| Sample Output 41 
 | 
| Author Kiki 
 | 
| Source 2008杭电集训队选拔赛——热身赛 
 | 
| Recommend lcy 
 | 
题目分析:
简单模拟。
代码如下:
/*
 * g.cpp
 *
 *  Created on: 2015年3月24日
 *      Author: Administrator
 */
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(){
	string str;
	while(getline(cin,str)){
		stack<char> st;
		int len = str.length();
		int i;
		for(i = 0 ; i < len ; ++i){//遍历整个字符串
			if(str[i] == '('){//如果当前字符是(
				st.push('(');//将当前字符入栈
			}else if(str[i] == ')'){//如果当前字符是)
				st.pop();//出栈一个(
			}else if(str[i] == 'B'){//如果已经找到礼物
				break;//跳出循环
			}
		}
		int cnt = 0;
		while(st.empty() == false){//计算栈中还有多少个(
			cnt++;
			st.pop();
		}
		printf("%d\n",cnt);
	}
	return 0;
}









