Problem of the day
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.
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.
For each test case, print the text, in the same format, obtained after removing the comments.
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.
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
8
/*Sample
test case */
main() {
// Declare variables here.
int a = 2, b = 3, sum;
sum = a + b; // Find sum
Return;
}
main() {
int a = 2, b = 3, sum;
sum = a + b;
Return;
}
Remove the line and block comments and print the resulting text. On removing comments, lines 1, 2 and 4 of the text becomes empty, so we do not output those lines.
2
Coding/* Block comment
Spanning multiple lines */ Ninjas
Coding Ninjas
Remove the block comments and print the resulting text. On removing the block comment, the implicit newline character also gets removed.