愚人節的禮物 |
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 32 Accepted Submission(s): 30 |
|
Problem Description
四月一日快到了,Vayko想了個愚人的好辦法——送禮物。嘿嘿,不要想的太好,這禮物可沒那麼簡單,Vayko爲了愚人,準備了一堆盒子,其中有一個盒子裏面裝了禮物。盒子裏面能夠再放零個或者多個盒子。假設放禮物的盒子裏再也不放其餘盒子。
用()表示一個盒子,B表示禮物,Vayko想讓你幫她算出愚人指數,即最少須要拆多少個盒子才能拿到禮物。 |
Input
本題目包含多組測試,請處理到文件結束。
每組測試包含一個長度不大於1000,只包含'(',')'和'B'三種字符的字符串,表明Vayko設計的禮物透視圖。 你能夠假設,每一個透視圖畫的都是合法的。 |
Output
對於每組測試,請在一行裏面輸出愚人指數。
|
Sample Input
((((B)()))()) (B) |
Sample Output
4 1 |
Author
Kiki
|
Source
2008杭電集訓隊選拔賽——熱身賽
|
for語句啊,左括號減去右括號測試
1 #include <cmath> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <string> 6 #include <cstdlib> 7 using namespace std; 8 9 const int maxn=1100; 10 char s[maxn]; 11 int cnt,l; 12 13 void close() 14 { 15 exit(0); 16 } 17 18 19 void init() 20 { 21 while (fgets(s,2100,stdin)!=NULL) 22 { 23 cnt=0; 24 l=strlen(s); 25 for (int i=0;i<l;i++) 26 { 27 if (s[i]=='B') 28 { 29 printf("%d\n",cnt); 30 } 31 if (s[i]=='(') 32 cnt++; 33 if (s[i]==')') 34 cnt--; 35 } 36 } 37 } 38 39 int main () 40 { 41 init(); 42 close(); 43 return 0; 44 }