Page 1 of 2

327 - Evaluating Simple C Expressions

Posted: Sat Sep 14, 2002 4:28 pm
by nejhum
can any one give me a sample input why problem #327 is WA?

Posted: Sat Sep 14, 2002 8:42 pm
by ..
hm....I guess there may be something like
a + + - b
in the input. At first I got WA on this problem, but after I try to remove all space from the input, I got accepted. So you can try to remove space from the input first. :D

Posted: Sat Sep 14, 2002 9:51 pm
by nejhum
here is the out put of my program;

Expression: a + + - b
value = -1
a = 2
b = 2

i think this is ok.

what do you think?

i have trancated the blanksalso..

nejhum

Posted: Sat Sep 14, 2002 11:27 pm
by Yarin
Here's some sample input and my programs (which is AC) output. Maybe it can help?
b++---c+d-c+b
z+d+c++-++b-a
++b-++c+--e-b+f++
--a-++b+c+a-c++
should yield
Expression: b++---c+d-c+b
value = 5
b = 3
c = 2
d = 4
Expression: z+d+c++-++b-a
value = 29
a = 1
b = 3
c = 4
d = 4
z = 26
Expression: ++b-++c+--e-b+f++
value = 6
b = 3
c = 4
e = 4
f = 7
Expression: --a-++b+c+a-c++
value = -3
a = 0
b = 3
c = 4

Posted: Sun Sep 15, 2002 5:34 am
by nejhum
dear yarin ,

thank you very much for your sample input data,
it helped me a lot to CORRECT my problem

nejhum :lol:

Posted: Wed Dec 11, 2002 2:35 am
by jonas
Yarin wrote:Here's some sample input and my programs (which is AC) output. Maybe it can help?

<snip input and output>
I could use some help with this one. I still get Wrong Answer, even though my program works with Yarin's input and output data. I am stumped.
:cry:

Posted: Thu Dec 12, 2002 5:39 pm
by MV
Have you considered the following cases?

-a
+a

Anyway, test cases like a+b-a won't be in the input.

Posted: Thu Dec 12, 2002 10:31 pm
by jonas
MV wrote:Have you considered the following cases?

-a
+a

Anyway, test cases like a+b-a won't be in the input.
I have intentionally ignored those cases, since unary plus and minus are not mentioned in the problem description.

But you are right about Yarin's test cases - they do contain some lines with "undefined behaviour".

Posted: Fri Dec 13, 2002 10:12 am
by MV
OK, you are rigth about the unary operations. Here are some more test cases and the output my AC program gives.
  • a + b
    b - z
    a+b--+c++
    c+f--+--a
    f-- + c-- + d-++e

    a--+b--+c--+d--+e--+f--+g--+h--+i++-j++-k++-l++-m++-n++-o++-p++-q++-r++-s+t-u+v
    --z+a--
    a
    z
    ++ x+--y+z++
    a++-c++-m+ + +o+k
output:
  • Expression: a + b
    value = 3
    a = 1
    b = 2
    Expression: b - z
    value = -24
    b = 2
    z = 26
    Expression: a+b--+c++
    value = 6
    a = 1
    b = 1
    c = 4
    Expression: c+f--+--a
    value = 9
    a = 0
    c = 3
    f = 5
    Expression: f-- + c-- + d-++e
    value = 7
    c = 2
    d = 4
    e = 6
    f = 5
    Expression:
    value = 0
    Expression: a--+b--+c--+d--+e--+f--+g--+h--+i++-j++-k++-l++-m++-n++-o++-p++-q++-r++-s+t-u+v
    value = -79
    a = 0
    b = 1
    c = 2
    d = 3
    e = 4
    f = 5
    g = 6
    h = 7
    i = 10
    j = 11
    k = 12
    l = 13
    m = 14
    n = 15
    o = 16
    p = 17
    q = 18
    r = 19
    s = 19
    t = 20
    u = 21
    v = 22
    Expression: --z+a--
    value = 26
    a = 0
    z = 25
    Expression: a
    value = 1
    a = 1
    Expression: z
    value = 26
    z = 26
    Expression: ++ x+--y+z++
    value = 75
    x = 25
    y = 24
    z = 27
    Expression: a++-c++-m+ + +o+k
    value = 11
    a = 2
    c = 4
    k = 11
    m = 14
    o = 15
There propably aren't any empty test cases :roll: in the real input, so those cases can be omitted when comparing the outputs.
Anyway, my program could be wrong in some cases too, though AC.

Posted: Fri Dec 13, 2002 12:18 pm
by jonas
Thank you for your help. I have modified my program to deal with empty lines, so now my output for the test cases you supplied matches yours exactly.

But alas... still WA.

help

Posted: Tue Feb 04, 2003 9:13 am
by sjn
i have passed all of the test data above

but still WA

who can help me :cry:


thx in advance :roll:

i got it

Posted: Wed Feb 05, 2003 5:50 pm
by sjn
At last i got AC :evil:

there is no input like following

-a
a--b
++a + ++a + ++a

all of the input are very strict

But i don't why my code submited twice and got WA & AC

line by itself and will contain no more than 80 characters.

Posted: Tue Jun 17, 2003 4:43 pm
by rodriwan
OK. Ive spent a lot of time trying to solve this problem.
After more than a week I decided to make the vector were I was reading the input bigger (5512 position, instead of 100 initialy). That made me get an accepted.

But in the problem specification it is really clear "Each of the expressions will appear on a line by itself and will contain no more than 80 characters.". He says "characters" not "valid characters", and, at least to me, space is a character also.

For those who are trying to solve this problem, just enlarge the input vector (at least it worked for me).

Posted: Tue Sep 07, 2004 5:18 am
by Betty
Yarin wrote:Here's some sample input and my programs (which is AC) output. Maybe it can help?
b++---c+d-c+b
should yield
Expression: b++---c+d-c+b
value = 5
b = 3
c = 2
d = 4
I get value = 4 and my program was AC

Posted: Wed Aug 10, 2005 11:36 pm
by jaracz
It can't be input like
a + ++a or a+ --a ...and so on
I mean it can't be same letter used a few times
cause it was written
Execute the statements generated in step 1, then those generated in step 3, and finally the one generated in step 2, in that order.
so at first calculate expresisons like ++a and so on
suppose it was such an input
--a + ++a
so according to problem description first calculate all values
so a = 1 then 0 then 1
and now calculate expression so it should be 1 + 1 so final value is 2
according to some of you guys it will be
--a + ++a so
(0) + (1) and value will be 1

that's why these input (b++---c+d-c+b) gave 2 different answers and is invalid so there mustn't be input like this

for those who still get WA:
consider this a+++++b case
and remember to clear string from spaces
i.e. string[remove(string,string+strlen(string),' ') - string] = '\0';
Regards