727 - Equation

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

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

727

Post by Hisoka »

Help, I try all sample I/O in that board, I pass all, but I always got WA too.
Can you give me more test to check my program, or you give me hint?? :cry:
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

may there are negatif input for this problem?

like this:
input = -1+2
output= 1-2+
:-?
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

Hello Hisoka, ... There will be no negative number. Each line in one test-case will only have 1 char.

Did you notice that this problem has multiple-input format ?

Try these test-cases:

Input

Code: Select all

7

1
+
2
-
3

1
+
2
*
3

(
1
+
2
)
/
(
3
-
4
)

(
(
1
+
2
)
*
(
3
-
4
)
+
5
)
/
(
6
+
7
)

(
1
*
(
2
+
3
+
(
4
*
5
)
)
+
1
)

(
(
(
1
)
)
)

1
Output

Code: Select all

12+3-

123*+

12+34-/

12+34-*5+67+/

123+45*+*1+

1

1
Good luck,

-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

Hello turuthok, I pass for all your sample I/O with my program when I got WA. And my program is multiple input too. :cry:
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I got the same problem with this question. I use simple expression's parser to create postfix notation.
I pass tests from you, turothok, and also pass tests given in other threads by Ivan Golubev
Maybe I miss something ? Please help, because problem seems to be easy ...

Dominik Michniewski
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)
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

I got AC now, thanx turuthok :D

to dominik:
I try your program from your previous post, I got this.

Code: Select all

input:
1
+
2
*
3

Code: Select all

output:
+23*
you always got Wrong answer when your first input. but you get true output for your next output. so I think your mistake only from your I/O, not your algo. :wink:
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

Well, I'm getting sick & tired of this problem. I struggled with it 9 months ago, and I'm stil struggling with it now.
Can anybody, once and for all, put into plain english what is wrong with the input to this problem and how we are supposed to deal with it. I'm shure I handle all the cases in all the threads properly, but WA is all I get.

Why don't the judges correct a problem that is so long known to exist?

HELP ME, please...
Andrey Mokhov
Experienced poster
Posts: 128
Joined: Fri Nov 15, 2002 7:45 am
Location: Kyrgyzstan

Post by Andrey Mokhov »

Hello, everyone!

In fact I might be a lucky person as I got AC on the problem after my first submission. 8)

Firstly I want to say that I didn't handle cases all you talking about :

Code: Select all

1(2+3)4 
or
(1*2*3*4*5)6+2-5*9+1
I guess there is no expressions where two operands have no operator between.

To get the postfix notation I use simple stack method and it works.

Anyway I'm not sure that the judge data is correct but my AC says me that there can be two cases:
- Judge is right.
- Judge and me are equally wrong.

I guess the first is more possible than the second. :wink:

Good luck!
Andrey.
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

No,
I have submitted my test program again, and find that the judge input isn't corrected yet.

Actuallly it is possible to get accepted w/o specially handled the incorrect input, if you are lucky enough that your program can output the same thing as the sample output.
My signature:
  • Please make discussion about the algorithm BRFORE posting source code.
    We can learn much more in discussion than reading source code.
  • I HATE testing account.
  • Don't send me source code for debug.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

I hate it, but I'll add my code to the long list of published sources on this matter. It's a plain vanilla implementation of a RDP without any syntax checking. It glues together all expressions in one case, like Ivan Golubjev suggested, so it can handle cases like

Code: Select all

(1+2)3 -> 12+3
12 -> 12
1(7*8)6 -> 178*6
etc.
Please give me some feedback.

[pascal]program p727;

var
infix,postfix:ansistring;
parsepos,writepos:integer;

procedure expression;forward;

procedure factor;
begin
case infix[parsepos] of
'0'..'9':begin
inc(writepos);
postfix[writepos]:=infix[parsepos];
inc(parsepos);
end;
'(':begin
inc(parsepos);
expression;
inc(parsepos); //eat ')'
end;
end;
end;

{
ALL BUT THE CRITICAL SECTION REMOVED,
SINCE IT'S A SPOILER :)
}

[/pascal]
Last edited by little joey on Sat Apr 19, 2003 11:51 am, edited 1 time in total.
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

Here this a part from my code:[c]void getexpression(void);

void getfact(void)
{
if (*st == '(') {
st++;
getexpression();
assert(*st == ')');
st++;
if (isdigit(*st)) {
printf("%c", *st);
st++;
}
return;
}
while (isdigit(*st)) {
printf("%c", *st);
st++;
}
}[/c]
The fix itself here is:[c] if (isdigit(*st)) {
printf("%c", *st);
st++;
}[/c]
With this modification I've got accepted.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

Thanks man!!!

That did it. Finaly got AC.

I'm not shure, but I think reading more than one digit in getfact() could be essential too.

Hope to help you back someday,

-little joey
Farid Ahmadov
Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan

727

Post by Farid Ahmadov »

I know that there is an input here like:

1(2+4)3 or 1*2(1+2)1+2

I have checked it many times
I guess that it means that there is not only one input, but more than one...
I think the answers are:

124+3 and 12*12+12+

I ask ones who solved this problem and got AC.
Please explain it if you can
_____________
NO sigNature
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

The answer is in the previous thread; especialy the answer Ivan Golubev gave to my question. I added two 'features' to my code:

1. Read all occurring digits and print them, even if you expect only one;
2. Read any digit that follows a closing bracket and print it.

This means that for the input
12+3
I print
123+
and for the input
(1+2)3
I print
12+3
and finally got AC.
Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

727

Post by Zhao Le »

I know and I also hate to post my code here.
BUT I don't know how to get rid of Runtime ERROR(SISIGIV)

The code is deleted.
Last edited by Zhao Le on Thu Jan 29, 2004 4:17 pm, edited 1 time in total.
AC makes me feels good,
But WA makes me thinks hard.
Post Reply

Return to “Volume 7 (700-799)”