Page 3 of 5
Posted: Fri Dec 19, 2003 6:56 pm
by pavelph
Hello! Thank you very much.
I take into account your message and correct code. But it`s still WA:
[pascal]...
if s='' then begin writeln(l); continue; end;
if (s[1]='e') or (s[1]='E') then delete(s, 1, 1)
else begin writeln(i); continue; end;
f:=true;
if (s[1]='-') or (s[1]='+') then delete(s, 1, 1);
if s='' then begin writeln(i); continue; end;
for n:=1 to length(s) do if not ((s[n]>='0') and (s[n]<='9')) then f:=false;
if f then writeln(l) else writeln(i);
end;
[/pascal]
And
Output
Code: Select all
123.456+789 is illegal.
123.456 is legal.
123.456e+789 is legal.
123.456E-789 is legal.
123.456e is illegal.
123.456+ is illegal.
123.456E- is illegal.
123e456 is legal.
123E+456 is legal.
123.e456 is illegal.
123.E-456 is illegal.
+123.e456 is illegal.
-123e456 is legal.
+123e-456 is legal.
+ is illegal.
+e is illegal.
e123 is illegal.
e-12 is illegal.
-e123 is illegal.
+E+123 is illegal.
I think it`s true. But maybe...

Posted: Sat Dec 20, 2003 2:23 am
by Sanya
Hello, pavelph. One more bug found

Your prog outputs '1e+ is legal.'
I suggest you following changes:
[pascal]
...
if (s[1]='-') or (s[1]='+') then delete(s, 1, 1);
if s='' then f:=false else
begin
f:=true;
for n:=1 to length(s) do if not ((s[n]>='0') and (s[n]<='9')) then f:=false;
end;
...
[/pascal]
and notice my previous message
[pascal]
if (s[1]='e') or (s[1]='E') then begin delete(s, 1, 1); f:=true; end
else begin writeln(i); continue; end;
[/pascal]
because you wrote
[pascal]
if (s[1]='e') or (s[1]='E') then delete(s, 1, 1)
else begin writeln(i); continue; end;
[/pascal]

Posted: Sun Dec 28, 2003 8:08 pm
by pavelph

My prog for all inputs give me absolutly right outputs. And what is wrong?????
HELP ME PLEASE!!!
[pascal]
program acm325;
var n: byte;
s, l, i: string;
f: boolean;
begin
l:=' is legal.';
i:=' is illegal.';
s:='a';
while true do begin
readln(s);
if s[1]='*' then break;
while s[1]=' ' do delete(s, 1, 1);
while s[length(s)]=' ' do delete(s, length(s), 1);
write(s);
{Check that on the begining of line number or number with + / -}
f:=false;
if (s[1]='+') or (s[1]='-') then delete(s, 1, 1);
while (s[1]>='0') and (s[1]<='9') and (s<>'') do begin delete(s, 1, 1); f:=true; end;
if (not f) or (s='') then begin writeln(i); continue; end;
{If s[1]='.' => next will be number}
f:=false;
if s[1]='.' then begin
delete(s, 1, 1);
if (s[1]<'0') or (s[1]>'9') then begin writeln(i); continue; end;
while (s[1]>='0') and (s[1]<='9') and (s<>'') do delete(s, 1, 1);
end;
if s='' then begin writeln(l); continue; end; {Number like 1.1 is OK}
if (s[1]='e') or (s[1]='E') then delete(s, 1, 1) {If s<>'' then next 'e'}
else begin writeln(i); continue; end;
f:=true;
if (s[1]='-') or (s[1]='+') then delete(s, 1, 1);
if s='' then begin writeln(i); continue; end;
for n:=1 to length(s) do if not( ((s[n]>='0') and (s[n]<='9')) ) then f:=false;
if f then writeln(l) else writeln(i);
end;
end.
[/pascal]
Posted: Fri Jan 02, 2004 7:04 am
by Observer
I've changed the line[pascal]if s[1]='*' then break;[/pascal]into[pascal]while s[1]='*' do write;[/pascal] and submitted it to the judge. To my surprise, this didn't give me a TLE, but a WA! See it yourself:
| 2187475 | 2004/01/02 05:02:02.854 | Wrong Answer | 0:00.002 | 64 | PASCAL |
That means your code never reaches the end of file. It has encountered a runtime error during execution (do you agree?).
So now we should see where the runtime error might have occurred...
One possible source of error is accessing non-existing cells in a string. This type of error is hard to be discovered in Windows, but not for the judge!! For example, the line:[pascal]while (s[1]>='0') and (s[1]<='9') and (s<>'') do delete(s, 1, 1); [/pascal]is not good enough. FreePascal supports shortcut evaluation, thus it is better to write:[pascal]while (s<>'') and (s[1]>='0') and (s[1]<='9') do delete(s, 1, 1); [/pascal]
There might be other similar glitches in your code. Try to correct them all!

THANKS
Posted: Fri Jan 02, 2004 12:02 pm
by pavelph
Thank you very much!!!
Now I got
ACCEPTED
Also thank to Sanya and Aleksandrs Saveljevs.
All that you said was very helpful for me.
Output specification?
Posted: Tue Feb 17, 2004 6:22 am
by Kentaro
Could someone who got AC please explain exactly how the output should be formatted?
For example, if there is whitespace embedded in the constant (thus making it illegal) should it be in the output? Should whitespace after the constant be in the output? The problem statement says little about the format of the output.
confusing?
Posted: Tue Feb 17, 2004 11:28 am
by sohel
To Kentaro:
You are right - the problem description does not give clear details about the output format.
For output : ignore the leading and trailing spaces but consider the spaces that are embedded in the string.

Posted: Tue Feb 17, 2004 6:05 pm
by Kentaro
Thank you very much. I will attempt the problem again.

stuck with 325 too
Posted: Wed Feb 18, 2004 1:32 pm
by WR
Code: Select all
Hello,
after testing 70+ cases (including all from the posts)
I still get WA too.
Maybe the problem is how to handle empty lines?
1) My program ignores all empty lines (empty line
means just eoln, not even spaces).
2) Does a line contain just spaces, it's considered
illegal.
--> WA
Alternative:
Lines that contain just spaces are ignored also.
--> WA, too
I didn't try to accept lines with blanks yet (meaning they are legal)
because I wasted too may submissions already.
Sample input and output follow
1E1
1e1
1E
1EE1
1 E1
.1E1
1E.1
1E1.1
++1E1
1E--1
1.1.1E1
abcd
1
1.1
0e-0
123.456+789
1e+
.1111
123.0e12.
123.0e12+
123.0e12-
EEEEEE
+++++++
.......
99
<- just end of line
++1E1
1E--1
6.2.
-.5
6..2
1.1.1E11
-75-
1E.1
.1E1
1E
1EE1
1.1.1E1
7.6e+12.5
1E1.1
+1.5e-1 2
+6-4.2
-75E-
-75E2-
-3.3e-9999999999999999999999999
<- exactly one space
1.1E1
1.0e-55
+4.1234567890E-99999
1.2
1
1.
123.e123123123123123123+123123123123123123123
0e-0
.1E1
-e-12
-1e-12
1E1
1e1
5e6
5.2 7
abcd
1.2 1.2
123-E12
123.0e12E
5 e*6
5 e 6
1 E1
6.5E
e-12
1e-12
1.2
*
What kind of input did I miss?
output follows
Code: Select all
1E1 is legal.
1e1 is legal.
1E is illegal.
1EE1 is illegal.
1 E1 is illegal.
.1E1 is illegal.
1E.1 is illegal.
1E1.1 is illegal.
++1E1 is illegal.
1E--1 is illegal.
1.1.1E1 is illegal.
abcd is illegal.
1 is illegal.
1.1 is legal.
0e-0 is legal.
123.456+789 is illegal.
1e+ is illegal.
.1111 is illegal.
123.0e12. is illegal.
123.0e12+ is illegal.
123.0e12- is illegal.
EEEEEE is illegal.
+++++++ is illegal.
....... is illegal.
99 is illegal.
++1E1 is illegal.
1E--1 is illegal.
6.2. is illegal.
-.5 is illegal.
6..2 is illegal.
1.1.1E11 is illegal.
-75- is illegal.
1E.1 is illegal.
.1E1 is illegal.
1E is illegal.
1EE1 is illegal.
1.1.1E1 is illegal.
7.6e+12.5 is illegal.
1E1.1 is illegal.
+1.5e-1 2 is illegal.
+6-4.2 is illegal.
-75E- is illegal.
-75E2- is illegal.
-3.3e-9999999999999999999999999 is legal.
1.1E1 is legal.
1.0e-55 is legal.
+4.1234567890E-99999 is legal.
1.2 is legal.
1 is illegal.
1. is illegal.
123.e123123123123123123+123123123123123123123 is illegal.
0e-0 is legal.
.1E1 is illegal.
-e-12 is illegal.
-1e-12 is legal.
1E1 is legal.
1e1 is legal.
5e6 is legal.
5.2 7 is illegal.
abcd is illegal.
1.2 1.2 is illegal.
123-E12 is illegal.
123.0e12E is illegal.
5 e*6 is illegal.
is illegal.
5 e 6 is illegal.
1 E1 is illegal.
6.5E is illegal.
e-12 is illegal.
1e-12 is legal.
1.2 is legal.
Posted: Thu Feb 19, 2004 2:55 am
by UFP2161
IF there is a blank line (after trimming leading and trailing whitespace), the exact output should be:
Note that there is a space at the beginning of the line.
Posted: Thu Feb 19, 2004 8:54 am
by WR
Thanks, but if you look at my sample output
(the 7th line from the bottom), that's exactly what I do.
But I'll try again with the same output when the original
line is completely empty (just end of line, no spaces).
Back in a couple of minutes.
OK, back again, still WA!
Posted: Thu Feb 19, 2004 10:04 am
by UFP2161
But you don't have any output for the
"just end of line" input line.
And the other line marked exactly one space.
Both those are perfectly good input lines that are deemed illegal.
Posted: Thu Feb 19, 2004 11:43 am
by WR
Thanks for the response, but I don't quite understand.
You're of course right when you say that there's no output
for the empty line. True. I changed this half an hour ago,
submitted again and it's still WA.
New sample input:
Code: Select all
99
<- 3 spaces
99
<- 2 spaces
99
<- 1 space
99
<- eol only
99
*
output:
Code: Select all
99 is illegal.
is illegal.
99 is illegal.
is illegal.
99 is illegal.
is illegal.
99 is illegal.
is illegal.
99 is illegal.
Is this what you mean?
Posted: Thu Feb 19, 2004 2:16 pm
by UFP2161
Yeah.. mm.. then there's something else wrong I guess =/
Posted: Fri Feb 20, 2004 12:20 am
by junbin
Try this:
Code: Select all
k__s_jhsfdkkjsa_df__sadf_s
__dsfgh_sdf_gk_dsf_
__2_2_3443_457_65
_2e3e2e2
_+e-2
_+2-1
_+2e-2
__+2e+2
__-2e-1-1_
_442
_3465374657846358634563865923569548236458263458623562835682346582364582364___
_34653746578463_5863456386592356_95482364582634586235_62835682346582364582364___
_45643856___
_4353_e_546456
_456456e345345___
_462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576__
_462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576+__
_462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576-_
_+462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576__
_462976592798713405193549823645926395628346589236458946e+4569223458726348563256238465872465876324576
_-462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576__
_462976592798713405193549823645926395628346589236458946e-4569223458726348563256238465872465876324576_
_+462976592798713405193549823645926395628346589236458946e-4569223458726348563256238465872465876324576_
_-462976592798713405193549823645926395628346589236458946e+4569223458726348563256238465872465876324576_
12e21
435e231e123e213
23e+355-14
+234+e234+E1234
3.2
459679346834596734956739476984396739476972394571936459823645863195629384658723653245235.37563286583645162847686587436587632475
457693476987495864364.5645634564564356e4563564564356543
457693476987495864364.5645634564564356e+4563564564356543
457693476987495864364.5645634564564356e-4563564564356543
+457693476987495864364.5645634564564356e4563564564356543
-457693476987495864364.5645634564564356e4563564564356543
457693476987495864364.+5645634564564356e4563564564356543
457693476987495864364.-5645634564564356e4563564564356543
*
1) Remove all spaces
2) Replace all _ with one space
(This is because the forum adds one space to the end of each line by itself
Code: Select all
k s jhsfdkkjsa df sadf s is illegal.
dsfgh sdf gk dsf is illegal.
is illegal.
2 2 3443 457 65 is illegal.
2e3e2e2 is illegal.
+e-2 is illegal.
+2-1 is illegal.
+2e-2 is legal.
+2e+2 is legal.
-2e-1-1 is illegal.
442 is illegal.
3465374657846358634563865923569548236458263458623562835682346582364582364 is illegal.
34653746578463 5863456386592356 95482364582634586235 62835682346582364582364 is illegal.
45643856 is illegal.
4353 e 546456 is illegal.
456456e345345 is legal.
462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576 is legal.
462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576+ is illegal.
462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576- is illegal.
+462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576 is legal.
462976592798713405193549823645926395628346589236458946e+4569223458726348563256238465872465876324576 is legal.
-462976592798713405193549823645926395628346589236458946e4569223458726348563256238465872465876324576 is legal.
462976592798713405193549823645926395628346589236458946e-4569223458726348563256238465872465876324576 is legal.
+462976592798713405193549823645926395628346589236458946e-4569223458726348563256238465872465876324576 is legal.
-462976592798713405193549823645926395628346589236458946e+4569223458726348563256238465872465876324576 is legal.
12e21 is legal.
435e231e123e213 is illegal.
23e+355-14 is illegal.
+234+e234+E1234 is illegal.
3.2 is legal.
459679346834596734956739476984396739476972394571936459823645863195629384658723653245235.37563286583645162847686587436587632475 is legal.
457693476987495864364.5645634564564356e4563564564356543 is legal.
457693476987495864364.5645634564564356e+4563564564356543 is legal.
457693476987495864364.5645634564564356e-4563564564356543 is legal.
+457693476987495864364.5645634564564356e4563564564356543 is legal.
-457693476987495864364.5645634564564356e4563564564356543 is legal.
457693476987495864364.+5645634564564356e4563564564356543 is illegal.
457693476987495864364.-5645634564564356e4563564564356543 is illegal.