#C14. Remove Comments from C++ Source Code
Remove Comments from C++ Source Code
Remove Comments from C++ Source Code
In this problem, you are given a C++ source code as input which may contain both single-line comments (starting with //
) and multi-line comments (enclosed between /*
and *\/
). Your task is to remove all comments from the source code.
The single-line comment begins with //
and continues until the end of the line, while the multi-line comment starts with /*
and ends with *\/
. The transformed code should preserve the original code structure except for the removed comments. All processing should occur using standard input and output.
No specific formulas are involved in this problem, but if needed, any formulas must be written in LaTeX format (e.g. $a^2 + b^2 = c^2$
).
inputFormat
The input is provided via stdin
and consists of a single string representing the entire C++ source code. The code may span multiple lines, and it may include both single-line comments and multi-line comments.
outputFormat
Output the transformed C++ source code with all comments removed. The result should be printed to stdout
. Extra whitespace at the beginning and end of the output should be trimmed.
#include
/* This is a
multi-line comment */
int main() {
// This is a single line comment
std::cout << "Hello, World!"; // another comment
return 0;
}
#include
int main() {
std::cout << "Hello, World!";
return 0;
}
</p>