325 - Identifying Legal Pascal Real Constants

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

Moderator: Board moderators

andrew10
New poster
Posts: 7
Joined: Wed Jan 08, 2003 10:18 am
Location: Indonesia

Post by andrew10 »

[Can you send me the answer to me too??? Please!!!
Send on andrew_baggio_10@yahoo.com. I really need your help!

Thank You
andrew10
New poster
Posts: 7
Joined: Wed Jan 08, 2003 10:18 am
Location: Indonesia

Please Help me everyone! 325 and 335!!!

Post by andrew10 »

Please give me the answer for problem number 325 and 335 in C Language! I really need it for my collegge assignment

Thank You
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Dear Andrew Baggio,

Why do you want just the answer ?
And after you get the answer, you can just submit it to Online Judge and get Accepted ?
Isn't that makes you feel satisfied (get Accepted with other person's answer) ? :wink:
Have you tried to make it by yourself ?
If you face any problems on 325, why don't you ask something about this problem on board, like deddy one and I will help you as far as I can, but not the answer, of course. :D
If you want, I can help you to send my AC exe file to you, and you can re-check your output with mine. Ok ? :wink:

I think ACM is the place where we can study together to improve our skill in programming, but not just a place to submit problems as many as possible. Isn't that right ? :wink:
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Dear deddy one,

You're right, e/E can only be used once like dot.
Have you got AC on this problem? If not, I'll give you another tips:
1. Using adjacent + or - means illegal (e.g: 6.5e--4 is illegal, +-1.34e9 is illegal but +3.6e13 is legal)
2. No space between real constant (e.g: 5 e 6 is illegal but 5e6 is legal)
3. Dot can't be placed before or after the real constant (e.g: .5e6 is illegal, 5e6. is illegal)

Good luck! :D
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

thx very much angga

I've found my tricky input
for future solver consider this input


123.e123123123123123123+123123123123123123123

is illegal


ps :
this problem must be faced with clear headed situation
don't try to code it under pressure like me, it can be a stress
full job

with almost the same logic thinking actually you can
try to solve 392 too (I got it AC on second submission)
in 325 I got more than 10 WA

well, actually not that same logic thinking , but in both
of my code for 325 and 392 need a lot of if's
(that's the similarity)
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Your input is off course illegal, and it's easy to deduce from input statement .... :)) this problem isn't involved with parsers of expressions, but it must check properly of constant :)))

So if whole input line cannot be constant - it's not constant :D

Regards
Dominik
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Have you tried to solve the problem by yourself ???
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Have you tried to solve the problem by yourself ??? :wink:
Tried it first, if you have any question, just put it on board.

Regards.
InOutMoTo
New poster
Posts: 18
Joined: Sun Aug 10, 2003 12:47 pm

Post by InOutMoTo »

Dominik Michniewski wrote:Try this method:

only same states are allowed, also create biggest figure of good constant, it is: x[.(x)+][{E|e}(x)+]
where (x)+ means one or more digit
[x] means optional part of expression
{x|y} means one and exactly one of specified in brackets values
I've got AC by using Dominik's method :lol:

But " x[.(x)+][{E|e}(x)+] " need to change into these segments :
" [+ or - or empty] [(x)+.(x)+] [E or e] [+ or - or empty] [(x)+] "
I succeeded at the second try.

Good luck :wink:
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Of course - I forget about signs in expression.... Sorry

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)
pavelph
Learning poster
Posts: 57
Joined: Wed Dec 10, 2003 7:32 pm
Location: Russia, Saint-Petersburg

325 [Pascal] Why WA?

Post by pavelph »

I don`t know why I get WA.
Here some inputs for this problem. Maybe I have incorrect output?!
Help me PLEASE!!!
INPUT

Code: Select all

1E1 
1e1 
1E 
1EE1 
1 E1 
.1E1 
1E.1 
1E1.1 
++1E1 
1E--1 
1.1.1E1 
abcd 
1 
1.1 
0e-0 
* 
OUTPUT

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.
Sanya
New poster
Posts: 5
Joined: Mon Oct 27, 2003 3:05 pm
Location: Ukraine

Post by Sanya »

Hello! I solved this problem. So maybe I can help you, but I need to see your source. Your output seems to be correct.
pavelph
Learning poster
Posts: 57
Joined: Wed Dec 10, 2003 7:32 pm
Location: Russia, Saint-Petersburg

Post by pavelph »

Hello Sanya! Thank you for reply.
Here my code for this problem:
[pascal]program acm325;
var n: integer;
s, l, i: string;
f: boolean;
begin
{ assign(input, 'input.txt');
reset(input);
assign(output, 'output.txt');
rewrite(output);}
l:=' is legal.';
i:=' is illegal.';
while not eof do begin
readln(s);
while s[1]=' ' do delete(s, 1, 1);
while s[length(s)]=' ' do delete(s, length(s), 1);
if s='*' then break;
f:=false;
write(s);
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;
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 begin delete(s, 1, 1); f:=true; end;
end;

if s='' then begin writeln(l); continue; end;
if (s[1]='e') or (s[1]='E') then delete(s, 1, 1); f:=true;
if (not f) or (s='') then begin writeln(i); continue; end;

f:=true;
if (s[1]='-') or (s[1]='+') then delete(s, 1, 1);
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]
So how you can see, I look into string from begin and to end according to orders.
Aleksandrs Saveljevs
New poster
Posts: 39
Joined: Fri Nov 14, 2003 11:18 pm
Location: Riga, Latvia
Contact:

Post by Aleksandrs Saveljevs »

You don't have to set "flag:=true" in "if s[1]='.' then" section.

Consider this input: 123.456+789
Your prog reaches '.', removes digits 456 and has it's flag happily set to true. It skips the following 3 "ifs", sees the + sign, removes 789 and thinks everything's OK, while it is not. :)

PS: Sorry, I missed the fact that there's no "begin-end" when you check if s[1] is in ['e', 'E'], so ignore the above stated. :oops: Still, your prog fails on 123.456+789.
Last edited by Aleksandrs Saveljevs on Fri Dec 19, 2003 6:48 pm, edited 2 times in total.
Sanya
New poster
Posts: 5
Joined: Mon Oct 27, 2003 3:05 pm
Location: Ukraine

Post by Sanya »

Try to replace line
[pascal]
if (s[1]='e') or (s[1]='E') then delete(s, 1, 1); f:=true;
[/pascal]
with following:
[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]
Post Reply

Return to “Volume 3 (300-399)”