Update appNew update is available. Click here to update.

Remove Comments

Posted: 24 Feb, 2021
Difficulty: Moderate

PROBLEM STATEMENT

Try Problem

You are given a text in the form of an array of strings. A string present at the (i+1)th index, can be assumed to be separated from the string at the ith index, by a newline character (i.e. ‘\n’).

In the given text, we have two types of comments: line comments and block comments.

The string “//” denotes the starting of a line comment, which represents that the rest of the characters to the right of this string and present in the same line, should be ignored.

And the strings “/” and “/” denote the starting and ending points of a block comment, which represents that all the characters between these two strings must be ignored. Note that block comments can span across multiple lines whereas line comments end at the same line.

Your task is to remove the comments from the given text and print the text in the same format.

Note:
The first comment is given precedence over the other i.e. if the string “//” occurs in a block comment, then it is ignored and/or if the string “/*” occurs in a line or a block comment, it is also ignored.

The starting and ending point of the block comment must be non-overlapping i.e. a string like “/*/” does not end the block comment, as the ending would be overlapping the beginning.

Every starting point of a block comment will have an ending point as well.

The (implicit) newline characters which may occur when a block comment spans multiple lines, must be deleted/removed.

The text doesn’t contain any single or double quotes characters.
Input format:
The very first line of input contains an integer ‘N’ denoting the number of lines in the given text. 

Now ‘N’ lines follow where the ith line contains a string that denotes the ith line of the text.
Output format:
For each test case, print the text, in the same format, obtained after removing the comments.
Note:
If a certain line of the text becomes empty after removing the comments, you must not output that line i.e. each string in the resulting text must be non-empty.

You do not need to print anything, it has already been taken care of. Just return the resulting text in the same format. 
Constraints:
1 <= N <= 100
0 <= Length of ith String <= 5 * 10^3

Where  ‘N’ represents the number of lines in the given text.

Time Limit: 1 sec