Page 1 of 1

622 - Grammar Evaluation

Posted: Tue Sep 02, 2003 9:05 pm
by nealzane
can someone offer some tricky i/o? i have tried following i/o, are they correct?

i tested with assert() and have not met yet any integer over 1000 in the
judge data, neither have i met any input string longer than 1024.

input (line before '((20*((((((((100)))))))*100)))' is a blank line):

Code: Select all

17
32
12+34
1*(2+3)+3
1(2+3)+3
qwe323
1*(2+3)+399
1*(1*(1*(1*(1*(1*(1*(1+1)+1)+1)+1)+1)+1)+1)*(8+1)
1* (1+ 2 + 3) * (1 + 3)+ (1 + 2)*8
2*1*1+1*1*1000*1*1000*1*1
1000 +   2000
1000 2000
1+2*3
1*2+3
(1*2)*(3)
1+2+3

((20*((((((((100)))))))*100)))
output:

Code: Select all

32
46
8
ERROR
ERROR
404
72
48
1000002
3000
ERROR
7
5
6
6
ERROR
200000

Posted: Wed Sep 03, 2003 11:55 pm
by little joey
My AC program prints 'ERROR' for lines with spaces in them. I don't know if there are such lines in the judge's input. I use a standard Pascal string to read the input, so no line is longer than 255 characters.
Hope it helps.

Posted: Thu Sep 04, 2003 2:28 pm
by nealzane
AC - thanks to little joey.

this problem has some un-reasonable tricks:
  • number 0 is treated as positive
  • number form like '+nnn' is not treated as a valid number
though it is friendly at some other points:
  • seems no line contains blank but all continuous characters
  • lines are not too long, as little joey confirmed, not longer than 255
  • don't need float, 32-bit integer is enough

Posted: Fri May 27, 2005 3:44 pm
by Sedefcho
In order to summarize the I/O from nealzane
below is some sample I/O from an ACC program.

Hope it might be helpful for someone.

Just to note that my program first truncates any leading
and trailing SPACEs and/or TABs and then checks the value
of the remaning string(expression string). On the contrary, if
there are SPACEs/TABs in ( internally in ) the expression string
my program prints ERROR. I am not sure this is very imporant
but using this approach we get ACC.


INPUT

Code: Select all

26
32
-12
+12
0
12+34
1*(2+3)+3
1(2+3)+3
qwe323
1*(2+3)+399
1*(1*(1*(1*(1*(1*(1*(1+1)+1)+1)+1)+1)+1)+1)*(8+1)
1*(1+2+3)*(1+3)+(1+2)*8
((-1)*9)
((1)*9)
((0)*(9))
1* (1+ 2 +  3) * (1 + 3)+ (1 + 2)*8
2*1*1+1*1*1000*1*1000*1*1
1000 +   2000
1000 2000
1+2*3
1*2+3
(1*2)*(3)
1+2+3
    (5)

((20*((((((((100)))))))*100)))
((20*((((((((100))))))))*100)))


OUTPUT

Code: Select all

32
ERROR
ERROR
0
46
8
ERROR
ERROR
404
72
48
ERROR
9
0
ERROR
1000002
ERROR
ERROR
7
5
6
6
5
ERROR
200000
ERROR

622

Posted: Sun Sep 03, 2006 4:39 pm
by murkho
i did some problem with grammer(bnf).But i am puzzled with 622.
can anybody give me some idea about how to select appropriate grammer out of the choices?

Waiting for your idea!!

Posted: Tue Oct 31, 2006 6:26 pm
by yiuyuho
Why is 0 treated as positive? That's mathematically incorrect!

Need some more IO, please.

Posted: Mon Apr 30, 2007 12:09 pm
by nymo
Please, can someone provide some more IO? please... I need help.
and can any line starts with spaces like

Code: Select all

1
                (5)
Thanks.

EDIT: I 'VE GOT ACC... I 've truncated all the spaces now...

clearing doubt for leading characters

Posted: Fri Jul 20, 2007 6:09 am
by zid_adrenalyns
It's unnecesary truncates any leading SPACEs and/or TABs.
for this input

Code: Select all

26
32
-12
+12
0
12+34
1*(2+3)+3
1(2+3)+3
qwe323
1*(2+3)+399
1*(1*(1*(1*(1*(1*(1*(1+1)+1)+1)+1)+1)+1)+1)*(8+1)
1*(1+2+3)*(1+3)+(1+2)*8
((-1)*9)
((1)*9)
((0)*(9))
1* (1+ 2 +  3) * (1 + 3)+ (1 + 2)*8
2*1*1+1*1*1000*1*1000*1*1
1000 +   2000
1000 2000
1+2*3
1*2+3
(1*2)*(3)
1+2+3
    (5)

((20*((((((((100)))))))*100)))
((20*((((((((100))))))))*100)))
My AC program output

Code: Select all

32
ERROR
ERROR
0
46
8
ERROR
ERROR
404
72
48
ERROR
9
0
ERROR
1000002
ERROR
ERROR
7
5
6
6
ERROR
ERROR
200000
ERROR

Re: 622 traps?

Posted: Thu Apr 17, 2008 12:06 am
by x140l31
hi, this is a valid input?

Code: Select all

3-4

output will be

Code: Select all

-1
?


can anyone give some inputs/outputs with subtractions and divisions?

thx

Re: 622 - Grammar Evaluation

Posted: Thu Apr 17, 2008 1:17 am
by Jan
Just check the grammar, there is no subtraction or division. So, the output of your case should be 'ERROR'.

Re: 622 - Grammar Evaluation

Posted: Thu Apr 17, 2008 8:12 pm
by x140l31
Jan wrote:Just check the grammar, there is no subtraction or division. So, the output of your case should be 'ERROR'.
oh! i didn't see it because the pdf version has an error

http://icpcres.ecs.baylor.edu/onlinejud ... /6/622.pdf

how I can report this error?

Re: 622 - Grammar Evaluation

Posted: Fri Apr 18, 2008 1:31 am
by Jan
I think both the html and the pdf are same. I haven't found any difference.

Re: 622 - Grammar Evaluation

Posted: Sat Apr 19, 2008 11:17 pm
by x140l31
Jan wrote:I think both the html and the pdf are same. I haven't found any difference.

see at first lines

pdf:
Using the following grammar:

<expression> := <component> | <component> + <expression>
<component> := <factor> | <factor> + <component>
<factor> := <positive integer> | (<expression>)
html:
Using the following grammar:

<expression> := <component> | <component> + <expression>
<component> := <factor> | <factor> * <component>
<factor> := <positive integer> | (<expression>)

Re: 622 - Grammar Evaluation

Posted: Sun Apr 20, 2008 1:55 am
by Jan
You are absolutely right! Sorry that I didn't notice it. So, the pdf is wrong. You should complain about this in the 'Bugs and Suggestions' section.