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