1990 ACM East Central Regional Programming Contest
Problem 2: Comment Removal
| Source file: |
prob2.c or prob2.pas |
| Input file: |
prob2.in |
| Output file: |
prob2.out |
The Problem
Given an arbitrary, syntactically correct, Pascal source program in the file
PROB2.IN you are to compress it according to the following guidelines,
applied in the order listed:
- Replace all sequences of blanks, except those within a string
constant, with a single blank. Recall that string constants are
delimited by single quotes ('), a string constant must contain at
least one character, and that two consecutive single quotes ('')
represent the single quote character.
e.g.,
the following are string constants
'this is a string constant'
'don''t you see the fun here?'
- eliminate all comments - comments start with (* and are terminated
with *) or they start with { and are terminated with }. Remove the
entire comment including the end markers (i.e., (*, *), { and }).
e.g.,
the following are comments:
(* here is a great comment *)
{ and here is a somewhat
longer one }
- eliminate any totally blank lines (i.e., any lines, after removing
any comments, which consist only of blanks and end-of-line
characters - if when printed, or displayed, a blank line would
occur, it should be eliminated.) You can assume there will be no
tabs or other unusual non-printing characters within the input.
Compress the input file into the output file PROB2.OUT using the rules
above. The results should result in a syntactically valid Pascal program;
albeit it in a somewhat less stylish form.
Example
Input
Program Test (input, output);
{ this is a great program }
Var X, Y : integer ;
begin
readln (X, Y);
writeln (X, ' This is Y ', Y, "Hi!') ;
end.
Output
Program Test (input, output);
Var X, Y : integer ;
begin
readln (X, Y);
writeln (X, ' This is Y ', Y, "Hi!') ;
end.