hdu1870 (April Fool's Day gift)---simple stack class

Source: Internet
Author: User

Click to open link

Problem Description April 1 is coming, Vayko think of a fool's good way-to give gifts. Hey, don't think too good, this gift is not so simple, vayko for a fool, prepared a pile of boxes, one of which contained a gift. You can put 0 or more boxes inside the box. Suppose the gift box is no longer placed in another box.

Use () to represent a box, b for a gift, Vayko want you to help her figure out the Fool's index, that is, the minimum number of boxes to be removed to get the gift.

Input This topic contains multiple sets of tests, please handle to the end of the file.
Each set of tests contains a string that is not more than 1000 in length, contains only ' (', ') ' and ' B ' three characters, representing the Vayko design of the gift perspective.
You can assume that each perspective picture is legal.

Output for each set of tests, please export the fool's index in one line.
Sample Input
B

Sample Output
41

Package Stack;import Java.util.scanner;public class P1870 {public static void main (string[] args) {Scanner sc=new Scanner ( system.in); while (Sc.hasnext ()) {String s=sc.nextline (); Stack stack=new stack (s.length ()); char[] Ch=s.tochararray (); for (int i=0;i<ch.length;i++) {if (ch[i]== ' (') { Stack.instack (Ch[i]);} else if (ch[i]== ') ') {Stack.outstack ();} Else{break;}} System.out.println (Stack.gettop ());}}} Class Stack{int Top=0;int maxlen;char[] stack;public Stack (int maxlen) {this.maxlen=maxlen;stack=new Char[this.maxLen] ;} public void Instack (char ch) {stack[top++]=ch;} public void Outstack () {top--;} public int GetTop () {return top;}}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu1870 (April Fool's Day gift)---simple stack class

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.