## 11070 - The Good Old Times

Moderator: Board moderators

### The WA persist

Thank, what is the AC output for:

Code: Select all
`-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3-1000/-3`
ivan.cu
New poster

Posts: 21
Joined: Sun Mar 19, 2006 7:50 pm
Location: Cuba

I've tried many I/O's but still got WA and don't know why.
It the case like ---9 vaild in this problem?

Can someone give me some I/O's?
xish
New poster

Posts: 5
Joined: Mon Feb 13, 2006 9:45 am

This is my code:
/* @JUDGE_ID: 18814EA G C++ */

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>

using namespace std;

struct Oper
{
long op;
long pri;
};

std::vector<double> number;
std::vector<Oper> operators;

double solve(istream &sin)
{
double ans;
double a,b,c;
double num;
long i;
Oper oper;
Oper run_op;
char ch,ch1;
ans = 0;
number.clear();
operators.clear();
ch1 = '+';
ch = sin.peek();
while (ch == '-' || ch == '+')
{
if (ch == '-')
{
if (ch1 == '-')
{
ch1 = '+';
}
else
{
ch1 = '-';
}
}
ch = sin.get();
ch = sin.peek();
}
sin >> num;
if (ch1 == '-') num = -num;
number.push_back(num);
while (sin.good() == true)
{
sin >> ch;
switch(ch)
{
case '+':
oper.op = 1;
oper.pri = 1;
break;
case '-':
oper.op = 2;
oper.pri = 1;
break;
case '*':
oper.op = 3;
oper.pri = 2;
break;
case '/':
oper.op = 4;
oper.pri = 2;
break;
}
if ((operators.empty()) || (operators.back().pri < oper.pri))
{
operators.push_back(oper);
}
else
{
while ((operators.empty() == false) && (operators.back().pri >= oper.pri))
{
b = number.back();
number.pop_back();
a = number.back();
number.pop_back();
run_op = operators.back();
operators.pop_back();
switch(run_op.op)
{
case 1:
c = a + b;
break;
case 2:
c = a - b;
break;
case 3:
c = a * b;
break;
case 4:
c = a / b;
break;
}
number.push_back(c);
}
operators.push_back(oper);
}
ch1 = '+';
ch = sin.peek();
while (ch == '-' || ch == '+')
{
if (ch == '-')
{
if (ch1 == '-')
{
ch1 = '+';
}
else
{
ch1 = '-';
}
}
ch = sin.get();
ch = sin.peek();
}
sin >> num;
if (ch1 == '-') num = -num;
number.push_back(num);
}
while (operators.empty() == false)
{
b = number.back();
number.pop_back();
a = number.back();
number.pop_back();
run_op = operators.back();
operators.pop_back();
if (run_op.pri < operators.back().pri && operators.empty() == false)
while (1)
{
i++;
cout << i << endl;
}
switch(run_op.op)
{
case 1:
c = a + b;
break;
case 2:
c = a - b;
break;
case 3:
c = a * b;
break;
case 4:
c = a / b;
break;
}
number.push_back(c);
}
ans = number[number.size() - 1];
return ans;
}

int main()
{
long i;
string input;
string temp;
istringstream sin;
double ans;
cout.setf(ios::fixed);
while (getline(cin,input))
{
sin.clear();
temp = input;
input = "";
for (i = 0 ; i < temp.size() ; i++)
{
if ((temp[i] >= '0' && temp[i] <= '9') || temp[i] =='.' || temp[i] == '+' || temp[i] == '-' || temp[i] == '*' || temp[i] == '/') input = input + temp[i];
}
sin.str(input);
ans = solve(sin);
cout << setprecision(3) << ans << endl;
}
return 0;
}
xish
New poster

Posts: 5
Joined: Mon Feb 13, 2006 9:45 am

Hi! I also have WA and I would like to know are there any inputs from the judge when there are multiple unary operators like: --2 ?
Tosgin
New poster

Posts: 2
Joined: Wed May 31, 2006 4:47 pm
Location: Bosnia and Herzegovina, Sarajevo

### Re: The WA persist

ivan.cu wrote:Thank, what is the AC output for:

Code: Select all
`-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3-1000/-3`

Code: Select all
`2000.0001666.6671333.3331000.000666.667333.333`

Martin Macko
A great helper

Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

xish wrote:This is my code:
...

Make sure you don't output -0.000 instead of 0.000 in cases such as -10*0.

Martin Macko
A great helper

Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Tosgin wrote:Hi! I also have WA and I would like to know are there any inputs from the judge when there are multiple unary operators like: --2 ?

The problem description allows them. If they are not in OJ's inputs, the inputs are weak. Anyway, you can easily check it by yourself by one extra submition.

Martin Macko
A great helper

Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

### I'm exhaust whit this problem!!

I suspect that the mistake is in floating point error whit Java, i try anything and nothing, i'm feeling bad for this, may be i make a terrible error and i cannot se it.
ivan.cu
New poster

Posts: 21
Joined: Sun Mar 19, 2006 7:50 pm
Location: Cuba

### Re: I'm exhaust whit this problem!!

ivan.cu wrote:I suspect that the mistake is in floating point error whit Java, i try anything and nothing, i'm feeling bad for this, may be i make a terrible error and i cannot se it.

Well, try to rewrite it to c/c++ and you'll see if java is the issue.

Martin Macko
A great helper

Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Hi all,

FOR THIS INPUT
Code: Select all
`-1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3+-1000/-3 -1000/-3+-1000/-3+-1000/-3-1000/-3+-1000/-3 -1000/-3+-1000/-3+-1000/-3-1000/-3 -1000/-3+-1000/-3+-1000/-3 -1000/-3+-1000/-3 -1000/-32*-0.5+-0.5*3+-15.5 1/2/2 -3.0 3 4.0+3.0/5.0 1*2*3+1+1*2+1*2*3*4 --9 -1-1+9/3 ---9 -9--+-9 100 -10+2+2-10*0100 -10+2+2--9 -1-1+9/3 ---9 -9--+-93.1*3.1---0.2`

MY PROGRAM GIVES THIS OUTPUT
Code: Select all
`2000.0001666.6671333.3331000.000666.667333.333-18.0000.250-3.0003.0004.60033.0009.0001.000-9.000-18.000100.000-6.0000.000100.000-6.0009.0001.000-9.000-18.0009.410`

So it seems my program's output matches all test
cases posted in this board thread. I still get WA though.

Can someone give me any other hint?
Or some more critical I/O?

Sedefcho
A great helper

Posts: 375
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

I don't think the input contains multiple sign operators like in "-++---+78", because my accepted program would return nonsense in such cases (I use sscanf to parse numbers, and sscanf can't handle multiple signs).

Do you have your precedence rules correct? I believe the problem description is incomplete without them, because these rules can be different for different countries and at different times (they recently changed them in Holland, if I remember correctly).

Anyway, in this problem '*' and '/' have the same precedence. '+' and '-' also have the same precedence, but lower than '*' and '/'.
input
Code: Select all
`10-8+510+8-510*8/510/8*5`
output
Code: Select all
`7.00013.00016.0006.250`

According to what I learned at school, the first answer should have been -3.000 and the last 0.250...

little joey
Guru

Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Interesting, I didn't know there were cases where + had higher precedence than - (or * than /). Do you happen to have some link handy to a document containing something like that?
Darko
Guru

Posts: 572
Joined: Fri Nov 11, 2005 9:34 am

I don't have a link, but I know that generations of school children in Holland learned the sentence "Mijnheer van Dale wacht op antwoord", where the first letters of each word gives the precedence of the mathematical operations:

M (machtsverheffen) = exponentiation
V (vermenigvuldigen) = multiplication
D (delen) = division
W (worteltrekken) = taking the square root
A (aftrekken) = subtraction

Probably after years of delibration in commitees, sub-commitees and sub-sub-commitees, and spending millions in governement money, it was decided that the order should be changed to 'what was normal for a pocket calculator', so it would be easier for the kids: to a) learn the rules, b) use a pocket calculator. This is incredibly stupid of course (as are most rules and regulations in my dear little country), because if you have more than one pocket calculator, chances are big that they don't work with the same rules (with my cheap calculator the result is given as soon as you press an operator-key, my scientific calculator delays the result of additions/substractions to see if the multiplication/division key is pressed later on, and my HP, which is my favourite, uses RPN).

little joey
Guru

Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

### Re: I'm exhaust whit this problem!!

Martin Macko wrote:
ivan.cu wrote:I suspect that the mistake is in floating point error whit Java, i try anything and nothing, i'm feeling bad for this, may be i make a terrible error and i cannot se it.

Well, try to rewrite it to c/c++ and you'll see if java is the issue.

I try again, now in C++ and my WA persist. Please, some one see my error?

Code: Select all
`Code was remove, i got AC now.`

I try all sample input that a found in this forum and i have correct output. Where is my problem, please is some one can see it?
Last edited by ivan.cu on Fri Aug 18, 2006 11:37 pm, edited 1 time in total.
ivan.cu
New poster

Posts: 21
Joined: Sun Mar 19, 2006 7:50 pm
Location: Cuba

Yes, I also still get WA although my program
produces right answers for all tests posted here.

Some more test cases?

Peter

Sedefcho
A great helper

Posts: 375
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

PreviousNext