[BOJ 6731] Comment removal
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
1
Time limit:
1.0s
Memory limit:
128M
Problem types
Allowed languages
Given an arbitrary, syntactically correct Pascal program, you are to compress it. (Note that you do not have to know the programming language Pascal to solve this problem; all relevant information is given below.) Here are the guidelines describing how to compress the program:</p>
- Replace all sequences of blanks, except those within a string constant, with a single blank. Also, remove all blanks at the beginning of a line and all blanks at the end of a line.
In Pascal, strings are delimited by single quotes (“’”). Inside a string, two consecutive single quotes denote a single quote character. Examples are
’this is a string’
’isn’’t this fun?’
Strings may not cross line boundries. - Replace all comments with a single space. (If this space comes next to another space, the two are compressed as described above.)
In Pascal, comments are enclosed by either “( · · · )” or “{ · · · }”, as in
( This is a comment! )
{ A comment with a ‘)’. }
( A ( comment )
Comments may span several lines. They may not be nested. - Eliminate totally blank lines, i.e., lines that contain only spaces (initially, or after comment removel).
- You can assume that the source contains no TABs or other non-printing characters (except, of course, line separators).
- You can assume that no source text line is longer than 255 characters.
The input file contains a syntactically correct Pascal program, like this:
{_The_famous_’Hello_world’_program_}
program__Hello__(output);
__(_no_declarations_)
begin
__WriteLn(’Hello_,__’’quaint’’__world_!’);
end.
(Note that space characters are shown as “_” to make them easier to spot.)
출력 형식
The output should be a compressed Pascal program. For example, the program shown above should be reduced to
program_Hello_(output); begin WriteLn(’Hello_,__’’quaint’’__world_!’); end.
예제 입력
{ The famous 'Hello world' program }
program Hello (output):
(* no declarations *)
begin
WriteLn('Hello , ''quaint'' world !');
end.
예제 출력
program Hello (output):
begin
WriteLn('Hello , ''quaint'' world !');
end.
Comments