723 - Comment Removal

All about problems in Volume 7. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

723 - Comment Removal

Post by little joey »

I noticed that all accepted submissions but one got Presentation Error, including mine. Two things:
- why is it permitted to have P.E. in a problem where it's all about removing spaces and empty lines?
- I'm almost certain my program outputs the correct format, so why do I get P.E.?

I'll temporarily attach my code to this posting, maybe someone can find my mistake. Please don't leach it!

Code: Select all

*** REMOVED ***
Last edited by little joey on Sun Aug 21, 2005 10:01 am, edited 1 time in total.
avm
New poster
Posts: 33
Joined: Sat Aug 20, 2005 9:59 pm
Location: St. Petersburg

Does judge output can compiled by Pascal compiler?

Post by avm »

I also don't know how receive AC for this problem.
Please clarify this Input:

Code: Select all

var i:integer{};
begin
for i:=1 to 10 do{}writeln('''''',i);
writeln (0, {LightGreen,} 0);
end.
My P.E. Output and syntactically invalid Pascal program:

Code: Select all

var i:integer;
begin
for i:=1 to 10 dowriteln('''''',i);
writeln (0, 0);
end.
My W.A Output and syntactically valid Pascal program:

Code: Select all

var i:integer
;
begin
for i:=1 to 10 do
writeln('''''',i);
writeln (0, 
 0);
end.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I just start to write a solution, but I think, that lines like

Code: Select all

for i:=1 to 10 do{}writeln('''''',i);
should be outputed as

Code: Select all

for i:=1 to 10 do writeln('''''',i);
Why?
Because any comment is a blank for compiler. So if we remove comment we can put a blank instead of it.
BTW. Very nice input :D

Best regards
DM

PS. [2 hours later] Why I am not surprised, that I am not get Acc , but WA? :lol:
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I have one more question:

For inputs like:

Code: Select all

Program x(input,output);
var x {

}:integer;
begin end.
output should be:

Code: Select all

Program x(input,output);
var x 
:integer;
begin end.
or

Code: Select all

Program x(input,output);
var x :integer;
begin end.
?

Could anyone who got accepted post some critical IO ? I try to find my mistake, but I don't have any idea what I can do wrong ...

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
avm
New poster
Posts: 33
Joined: Sat Aug 20, 2005 9:59 pm
Location: St. Petersburg

Some tests

Post by avm »

Since 21 August it is impossible receive P.E. for this problem.
http://online-judge.uva.es/board/viewtopic.php?t=8715
Input and output below doesn't contain trailing spaces.
Input:

Code: Select all

 {Don't replace sequences of blanks with a single blank after removing comments
 } {For more details read problem statement
 }
 (*
*
)
*)(* My pascal program fails on comment above *) Program p723(input,output);
{$D-,L-,I-,Q-,R-,S-,Y-}
var x {

}:integer;
procedure repeatuntilfalse;begin end;
begin
(* comments are removed and not replaced by blank!*)
(* This is an example that input and output programs can be different!!!*)
repeat{}until{}false;
end.
{My ACCEPTED Pascal programs works 0.131 seconds with 320Kb memory spent}
{Any hints how speed up Pascal I/O?}
{SetTextBuf function is restricted!}
AC output:

Code: Select all

  Program p723(input,output);
var x :integer;
procedure repeatuntilfalse;begin end;
begin
repeatuntilfalse;
end.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Nice input. I think that I know now what I am doing wrong ...

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I have no idea what's wrong with my code ...

I follow instructions from problem description and topic but I still got WA.
Could you help me avm ?

Best regards
DM

PS. Avm, I post you my code in C via private message. Maybe you could help me? If not - it will be good too :)
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
avm
New poster
Posts: 33
Joined: Sat Aug 20, 2005 9:59 pm
Location: St. Petersburg

Post by avm »

Input

Code: Select all

begin
writeln('(**)'{    *)}+'');
end.
Output

Code: Select all

begin
writeln('(**)'+'');
end.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Nice :oops:
I completly forgot about such things ...

Thanks avm :):)

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post by minskcity »

I cannot see where in the problem statement is says that the comments inside the string constants should not be removed (it certainly says so about the multiple spaces in a row, but not comments)... :-?
Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

Post by Erik »

Hi,

I tried all testcases in this topic and my program produced correct output.
After many tests I discovered that my program finds a string-constant in the input which is not terminated at the end of the line.
Could anyone verify this?
Of course it should not happen as it is invalid pascal. Hence I guess it doesn't which means I must handle comments the wrong way as my program then must miss some '-s.
I hope you can help me or provide additional testcases.

Cu, Erik :)
Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

Post by Erik »

Hello,

i finally got AC. It was a tricky but substantial error in my program.

Cu, Erik :)
LithiumDex
New poster
Posts: 44
Joined: Tue Jun 06, 2006 6:44 pm
Location: Nova Scotia, Canada
Contact:

Post by LithiumDex »

My program passes all the test cases here (the good ones anyway)

My questions are:

- Do we remove all trailing spaces from the end of a line?
- If the last line in the file does not end with a \n, should a \n be displayed?
- In pascal, this is a valid comment: { *).. not here?
- This sounds kinda dumb, but if you read the problem state literally, it's saying that we should even remove comment blocks within strings, is this correct?

[EDIT]

- No
- ?
- Yes
- No
- Look out for multiline strings! (AC)

Thanks again,
- Chris Adams
Blackwizard
New poster
Posts: 12
Joined: Fri May 25, 2012 5:36 pm

Clarification

Post by Blackwizard »

hi everyone...
anybody knows the output for my output?

input:

Code: Select all

begin;
myfunc { nothing } }
(* comment *  )   *)
          
(*
*
)
*)

end;
tnx...
Blackwizard
New poster
Posts: 12
Joined: Fri May 25, 2012 5:36 pm

723 - Comment Removal_Clarification

Post by Blackwizard »

hi everyone...
anybody knows the output for my output?

input:

Code: Select all

begin;
myfunc { nothing } }
(* comment *  )   *)
          
(*
*
)
*)

end;
tnx...
Post Reply

Return to “Volume 7 (700-799)”