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
Conduct a site research on a specific property using the concepts discussed during this week.
Anni [7]

Answer:Penis!

Explanation:

Haha! Enjoy your day! Hahahahaha!

8 0
2 years ago
Do you need a contractor to install nest thermostat
Natalka [10]

Answer:

Sometimes yes, sometimes you can do it yourself

Explanation:

Installing a Nest thermostat can be done yourself without an electrician in most cases. Nest thermostats are designed to work in homes without a common (“C”) wire. However, there are rare cases a C wire or other power-supply accessory may be required. An electrician is recommended in these rare cases.

5 0
3 years ago
you are a bank loan officer. carter has to come into your office and applied for a loan for a car.you ran his credit report, and
elena-14-01-66 [18.8K]

Answer:

Carter score falls within the range of scores, from 300 to 579, considered Very Poor. Score is significantly below the average credit score.

Explanation:

5 0
3 years ago
Use EBNF notation to describe the syntax of the following language constructs.
ZanzabumX [31]

Answer:

Following are the description to the given points:

Explanation:

To resolve basic design restrictions, EBNF has also been developed.This principle was its lack of support can identify repeatings easily. It implies that popular BNF models, like the description of a sequence of replicable elements, are complicated and rely on contra intuitive logical math.

To set a list of words divided by commas (e.g. john, coffee, logic) for instance, we would like to say something like "a list is a word accompanied by a few commas or terms." Through EBNF, they may say so. However, there have been no "many" alternatives in the standard BNF format. So, to describe something such as "a list is a term or a number accompanied by a pair with notation and script," you have to say the same thing. Which functions, although it is difficult, as it specifies a variety of lists instead of a specific list.

Essentially, "john, coffee, logic is John's list, accompanied by coffees or, and logic" would be the earlier link.  That's why in Option (a):

The return statement in Java is:

return ('”‘ (~[“] | ” [”e‘])*);

In option (c), it is the valid statement.

7 0
3 years ago
Binary Number Cards
Sedaia [141]

Answer:

13: 1101

5: 0101

10: 1010

2: 0010

Explanation:

The binary system, on the other hand, is a base-2 number system. That means it only uses two numbers: 0 and 1. When you add one to one, you move the 1 one spot to the left into the twos place and put a 0 in the ones place

what is done with the dice is to have an example of how binary numbers are made until 15

5 0
3 years ago
Other questions:
  • &gt;&gt;&gt; import math &gt;&gt;&gt; print(math.Pi) 3.141592653589793 &gt;&gt;&gt; def print_volume(): print ("What is the radi
    12·1 answer
  • Which is the last step in conducting a URL search?
    5·2 answers
  • You are running an art museum. There is a long hallway with k paintings on the wall. The locations of the paintings are l1, ...,
    13·1 answer
  • If a client is found _________ the NAP will attempt to make it _______. Group of answer choices A. non-compliant, compliant B. s
    13·2 answers
  • Justin has started a lawn mowing business in his neighborhood. He is running a weed-pulling special this month. What is the most
    8·2 answers
  • An end-user license agreement protects _____.
    7·1 answer
  • Will give brainliest
    8·1 answer
  • Which device allows you to convert sounds into digital format to be used on the computer​
    8·1 answer
  • Uh can somebody help me
    6·1 answer
  • to troubleshoot an output component or input device, the first step is to activate the input device that controls the first outp
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!