Hdu1847 gifts for yu'e

Source: Internet
Author: User

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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.