import java.util.Scanner; import java.util.Stack; public class Braces { public static String[] braces(String[] values) { String[] result = new String[values.length]; String s; for(int i = 0; i < values.length; i++) { s = values[i]; Stack<Character> stack = new Stack<>(); boolean status = true; for(int j = 0; j < s.length(); j++) { if(s.charAt(j) == '[' || s.charAt(j) == '{' || s.charAt(j) == '(') { stack.push(s.charAt(j)); } else if(s.charAt(j) == ']') { if(stack.isEmpty() || stack.pop() != '[') { status = false; } } else if(s.charAt(j) == '}') { if(stack.isEmpty() || stack.pop() != '{') { status = false; } } else if(s.charAt(j) == ')') { if(stack.isEmpty() || stack.pop() != '(') { status = false; } } } status = status & stack.isEmpty(); if(status) { result[i] = "YES"; } else { result[i] = "NO"; } } return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String[] data = new String[n]; for(int i = 0; i < data.length; i++) { data[i] = in.next(); } String[] result = braces(data); for(int i = 0; i < data.length; i++) { System.out.println(result[i]); } in.close(); } }
Java 8 Braces You are designing a compiler for a C++ program and need to check...
Java Input Format For Custom Testing The first line contains an integer, n, that denotes the number of elements in s. Each line i of the n subsequent lines (where 0 si<n) contains a string that describes s[i]. Sample Case 0 Sample Input For Custom Testing 4 code aaagmnrs anagrams doce Sample Output aaagmnrs code Explanation aaagmnrs and anagrams are anagrams, code and doce are anagrams. After sorting aaagmnrs comes first. Sample Case 1 Sample Input For Custom Testing 4...
Can someone code this asap? Use any language that you want. 2. Ancestral Names Given a list of strings comprised of a name and a Roman numeral, sort the list first by name, then by decimal value of the Roman numeral. In Roman numerals, a value is not repeated more than three times. At that point, a smaller value precedes a larger value to indicate subtraction. For example, the letter I represents the number 1, and Vrepresents 5. Reason through...
IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...
in C++ and comments please for better understanding 3. How Will You Compare? Write a Comparator class with the following 3 overloaded compare methods: 1. boolean compare(int a, int b): Return true if int a = int b, otherwise return false. 2. boolean compare(string a, string b): Return true if string a = string b, otherwise return false. 3. boolean compare(int[] a, int[] b): Return true if both of the following conditions hold true: O Arrays a and b are...
I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...
I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...
1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...
I need a java flowchart for the following code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter the input size: "); int n=sc.nextInt(); int arr[]=new int[n]; System.out.print("Enter the sequence: "); for(int i=0;i<n;i++) arr[i]=sc.nextInt(); if(isConsecutiveFour(arr)) { System.out.print("yes the array contain consecutive number:"); for(int i=0;i<n;i++) System.out.print(arr[i]+" "); ...
Java 8 9m left Jav 27 28 ALL 29 0 Given an integer array, separate the values of the array into two subsets, A and B, whose intersection is null and where the addition of the two subsets equals the entire array. The sum of values in set A must be strictly greater than the sum of values in set B, and the number of elements in set A must be minimal. Return the values in set A in increasing...
Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...