The third session of Blue Bridge Cup Javac Group _ bracket Problem

Source: Internet
Author: User

/* (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

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.