You are on page 1of 2

LAB4 Problem A: A user is typing a sentence using his keyboard.

He uses only the keys, 'a' - 'z', H (home) and E(end). Given the sequence of key presses, find the line that is printed on the screen finally. Initially, a cursor is placed at the beginning of empty line and the following actions are performed with each key stroke. - when 'a'-'z' is pressed, its printed at current cursor position after moving the rest of the string to right. For eg. If the current cursor position is at t in the string "deter", pressing a 'x' key results in the string "dexter". - when 'H' is pressed, cursor moves to the beginning. For eg: pressing 'H' when we have "apple" results in string "apple" - when 'E' is pressed, cursor moves to the end of the string. For eg: pressing 'E' when we have "apple" results in string "apple " Its just like any normal editors we use. Try it out pressing 'a' - 'z', Home and End keys to get a feel of it :) Use only C to code this problem. For other problems you can use C/C++ Input: Only one line, contains a long string of at most 100000 valid characters Output: Print the final string in a single line, followed by a '\n' ( just print a new line, no need to display '\n' ) Constraints: Time Limit : 1s Sample Case 1: Input: atHc Output: cat\n Explanation: " " "a " "at " "at" "cat"

Sample Case 2: Input: rHsEocHpEkHaEs

Output: apsrocks\n Explanation: Of course, whats there to explain... just experience it ! Problem B: Youre given a non empty string made of only opening and closing braces. Your task is to find the minimum number of operations needed to make the string stable. The definition for being stable is as follows: An empty string is stable. 1. If S is stable, then {S} is also stable. 2. If S and T are both stable, then ST (the concatenation of the two) is also stable. All of these strings are stable: {}, {}{}, and {{}{}}; But none of these: }{, {{}{, nor {}{. The only operation allowed on the string is to replace an opening brace with a closing brace, or visa-versa. Input: First Line would be the T, number of Test Cases. Following T lines would be a non empty string of opening and closing braces and nothing else. No string has more than 100000 braces. All sequences are of even length. Output: for Each Test Case print N followed by a '\n' ( just print a new line, no need to display '\n' ) Where N is the minimum number of operations needed to convert the given string into a balanced one Sample Case : Input: 3 }{ {}{}{} {{{} Output: 2 0 1 Explanation: for }{ ,you need to operate on both the braces to make the string balanced. for , it is already balanced. For {{{}, you just need to convert the second brace to the closing brace.

You might also like