11070 - The Good Old Times

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

Moderator: Board moderators

ivan.cu
New poster
Posts: 21
Joined: Sun Mar 19, 2006 7:50 pm
Location: Cuba

The WA persist

Post by ivan.cu » Mon Aug 14, 2006 3:39 pm

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

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

Post by xish » Mon Aug 14, 2006 6:16 pm

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

Post by xish » Mon Aug 14, 2006 6:45 pm

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 >= '0' && temp <= '9') || temp =='.' || temp == '+' || temp == '-' || temp == '*' || temp == '/') input = input + temp;
}
sin.str(input);
ans = solve(sin);
cout << setprecision(3) << ans << endl;
}
return 0;
}

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

Post by Tosgin » Mon Aug 14, 2006 7:01 pm

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 ?

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: The WA persist

Post by Martin Macko » Mon Aug 14, 2006 7:28 pm

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.000
1666.667
1333.333
1000.000
666.667
333.333

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Mon Aug 14, 2006 7:37 pm

xish wrote:This is my code:
...
Make sure you don't output -0.000 instead of 0.000 in cases such as -10*0.

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Mon Aug 14, 2006 7:40 pm

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.

ivan.cu
New poster
Posts: 21
Joined: Sun Mar 19, 2006 7:50 pm
Location: Cuba

I'm exhaust whit this problem!!

Post by ivan.cu » Tue Aug 15, 2006 12:19 am

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.

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: I'm exhaust whit this problem!!

Post by Martin Macko » Tue Aug 15, 2006 10:50 am

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.

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Fri Aug 18, 2006 12:28 pm

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/-3
2*-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*0
100 
-10+2+2
--9 
-1-1+9/3 
---9 
-9--+-9
3.1*3.1---0.2
MY PROGRAM GIVES THIS OUTPUT

Code: Select all

2000.000
1666.667
1333.333
1000.000
666.667
333.333
-18.000
0.250
-3.000
3.000
4.600
33.000
9.000
1.000
-9.000
-18.000
100.000
-6.000
0.000
100.000
-6.000
9.000
1.000
-9.000
-18.000
9.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?
Thanks in advance.

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Fri Aug 18, 2006 1:13 pm

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+5
10+8-5
10*8/5
10/8*5
output

Code: Select all

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

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Fri Aug 18, 2006 3:45 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?

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Fri Aug 18, 2006 4:37 pm

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
O (optellen) = addition
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).

ivan.cu
New poster
Posts: 21
Joined: Sun Mar 19, 2006 7:50 pm
Location: Cuba

Re: I'm exhaust whit this problem!!

Post by ivan.cu » Fri Aug 18, 2006 5:55 pm

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.

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Fri Aug 18, 2006 6:15 pm

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

Some more test cases?

Peter

Post Reply

Return to “Volume 110 (11000-11099)”