1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
wolverine [178]
3 years ago
13

Programming challenge description: Given a string comprising just of the characters (,),{,},[,] determine if it is well-formed o

r not. Input: Your program should read lines from standard input. Each line contains a string comprising of the characters mentioned above. There is no whitespace between characters. Output: Print out True if the string is well-formed, False otherwise.
Computers and Technology
1 answer:
nadezda [96]3 years ago
5 0

Answer:

Employing Java language,

Explanation:

//for using stack data structure

import java.util.Stack;

//class definition

public class BracketMatch {

   //function to find the string is well formed or not

   public static boolean isWellFormed(String str) {

       //variable to store the character value

       char ch;

       //check if the first character itself is the end of the brackets

       if (str.charAt(0) == ')'||str.charAt(0) =='}'||str.charAt(0) ==']')

           return false;

       //creating a stack of character type

       Stack<Character> stack = new Stack<Character>();

       //iterating through the characters in string

       for(int i=0; i < str.length(); i++) {

           //storing the current character from the string in the variable

           ch = str.charAt(i);

           if(ch == '('||ch=='{'||ch=='[')

               //if the character is starting of the brackets push it into stack

               stack.push(ch);

           else if(ch == ')')

               //if it is closing bracket and the stack is empty then the string is not well formatted

               if(stack.empty())

                   return false;

               else if(stack.peek() == '(')

                   stack.pop();

               else

                   return false;

           else if(ch == '}')

               if(stack.empty())

                   return false;

               else if(stack.peek() == '{')

                   stack.pop();

               else

                   return false;

       }

       //returning the stack content, if the string will be well formed the stack would be empty

       //after all the operations

       return stack.empty();

   }

   //main method

   public static void main(String[] args) {

       //calling function to find if the string is welll formatted or not

       System.out.println(isWellFormed("{}"));

       //calling function to find if the string is welll formatted or not

       System.out.println(isWellFormed("([)]"));

   }

}

You might be interested in
A picture drawn in 3 d is called?​
Varvara68 [4.7K]

Answer:

autostereogram

Explanation:

that^

6 0
3 years ago
Read 2 more answers
What is the best game of 2020 in pc​
dybincka [34]

Answer:we have games like alien wars call of duty astro avengers

Explanation:8

8 0
3 years ago
Read 2 more answers
United Broke Artists (UBA) is a broker for not-so-famous artists. UBA maintains a small database to track painters, paintings, a
lions [1.4K]

Answer:

Check the explanation

Explanation:

Kindly check the attached image below to see the relation and the table names.

7 0
3 years ago
Read 2 more answers
Please please help me in my question please
NeTakaya
The internet is a vast network that connects computers, cellular devices, and cable together from all over the world. There is wireless internet (Wi-Fi) which doesn’t use lines/cables to connect to devices. Cellular technology provides wireless internet access through cellphones. Finally there is satellite which travels an enormous distance from Earth to a satellite.
3 0
3 years ago
Read 2 more answers
Which specific attribute of a team player helps remove ambiguity from tasks?
Rama09 [41]
If a team player knows how to follow the rules, ambiguities can be prevented. Each member would be guided by specific details of their tasks and procedures. There is a clear definition of work premises that can avoid overlapping of work. This can give better productive results.
5 0
3 years ago
Read 2 more answers
Other questions:
  • What is working with others to find a mutually agreeable outcome?
    6·1 answer
  • Which of the following is an example of a formal business standard
    14·2 answers
  • Which type of market are you in if your firm, along with three other firms, controls 95% of the total music industry?
    13·1 answer
  • Finish the statement below to correctly describe the Defense Enrollment Eligibility Reporting System (DEERS). DEERS is a central
    6·1 answer
  • We are building a word processor and we would like to implement a "reflow" functionality that full-justifies text.Given a maximu
    12·1 answer
  • Advantages of e commerce
    14·1 answer
  • Do you know some website that can make a questionnaire? And I can use the link then put up on the social media so that everyone
    7·2 answers
  • Use the ________ property in the html link tag to to associate a web page with a style sheet for printing.
    5·1 answer
  • Mille gets a text from her friend asking if she wants to come over. It seems like a bit of a hassle to go to her friend's house,
    9·1 answer
  • In what year was the first permanent photographic image created?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!