This question is actually not the same as the question of the suffix expression. You don't need to consider the question of matching brackets. Therefore, you only need to add a left brace before finding the letter, and then subtract one from the right brace.
Description
March April 1 is approaching. vayko thought of a good way to give gifts to fools. Hey, don't think too well. This gift is not that simple. vayko has prepared a bunch of boxes for the sake of fools, and a box contains a gift. There can be zero or multiple boxes in the box. Suppose there are no other boxes in the box where the gift is given.
Use () to represent a box, B to represent a gift, and vayko wants you to help her calculate the fool's index, that is, the minimum number of boxes to be split to get a gift.
Input
This topic contains multiple groups of tests. Please process it until the end of the file.
Each group of tests contains a string of no more than 1000 characters including '(', ')' and 'B', representing the gift perspective designed by vayko.
You can assume that each perspective image is valid.
Output
For each group of tests, please output the fool's index in one row.
Sample Input
((((B)()))())(B)
Sample output
41
#include <string.h>#include <stdio.h>int main(){ int count, i, k; char s[1010]; while(~scanf("%s",s)) { count = 0; k = strlen(s); for(i = 0; i < k; i++) { if(s[i] == '(') { count++; } else if(s[i] == ')') count--; else break; } printf("%d\n", count); } return 0;}