/* (Start of program header comment)
* Copyright and version Declaration section of the program
* Copyright (c) 2016, Guangzhou Science and Technology Trade Vocational College, Department of Information Engineering students
* All rights reserved.
* File name: Blue Bridge Cup title
* Author: Pengjunhau
* Completion Date: April 01, 2016
* Version number: 001
* Description part of task and solution method
* Input Description:
* Description of the problem:
The following code is used to determine if the parentheses in a string match
The so-called match refers to the different types of parentheses that must be echoed around each other, but not cross
For example:
.. (.. [..]..).. is permissible.
.. (... [...) ....] .... It's forbidden.
For the test case in the main method, you should output:
False
True
False
False
Import java.util.*;
public class A22
{
public static Boolean Isgoodbracket (String s)
{
Stack<character> a = new stack<character> ();
for (int i=0; i<s.length (); i++)
{
char C = S.charat (i);
if (c== ' (') a.push (') ');
if (c== ' [') A.push ('] ');
if (c== ' {') A.push ('} ');
if (c== ') ' | | c== '] | | c== '} ')
{
if (____________________) return false; Blanks
if (A.pop () = c) return false;
}
}
if (___________________) return false; Blanks
return true;
}
public static void Main (string[] args)
{
System.out.println (Isgoodbracket ("... (.. [.)..]. {. (..).} ..."));
System.out.println (Isgoodbracket ("... (.. [...]. (.).) {. (..).} ..."));
System.out.println (Isgoodbracket ("... [...]. (.).) {. (..).} ..."));
System.out.println (Isgoodbracket ("... (.. [...]. (.).) {. (..) ...."));
}
}
* Program output:
* End of comment on the program head
*/
On the code:
if (A.empty ()) return false; Blanks
if (!a.empty ()) return false; Blanks
The third session of Blue Bridge Cup Javac Group _ bracket Problem