(Hdu step 8.1.7) Gifts for yu'e (basic use of stacks -- evaluate the number of characters before a specific character & #39; (& #39;), hdu8.1.7

Source: Internet
Author: User

(Hdu step 8.1.7) Gifts for yu'e (basic use of stacks-evaluate the number of '(' before a specific character), hdu8.1.7

Question:

A gift for the Fool's Day
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 49 Accepted Submission (s): 44
 
Problem Description 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 question contains multiple groups of tests, please process 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
 
AuthorKiki
Source2008 select-out competition-warm-up competition
Recommendlcy


Question Analysis:

Simple simulation.


The Code is as follows:

/** G. cpp ** Created on: March 24, 2015 * 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) {// traverse the entire string if (str [I] = '(') {// if the current character is (st. push ('); // import the current character to the stack} else if (str [I] =') {// if the current character is) st. pop (); // an out-of-stack (} else if (str [I] = 'B') {// if the gift break has been found; // skip loop} int cnt = 0; while (st. empty () = false) {// how many (cnt ++; st. pop () ;}printf ("% d \ n", cnt) ;}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.