10700 - Camel trading

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

Moderator: Board moderators

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

10700 Why WA???

Post by Morning » Sat Sep 25, 2004 5:46 pm

[cpp]
#include <iostream>
using namespace std;
#define isNumber(c) (c >= '0' && c <= '9')

class Stack
{
public:
Stack();
void push(int n);
long long pop();
long long point;
long long data[32];
};
Stack::Stack()
{
point = 0;
}
void Stack::push(int n)
{
data[point++] = n;
}
long long Stack::pop()
{
return data[--point];
}

long long max(char str[128])
{
long long n = 0;
Stack *s = new Stack();
for (int i = 0;str != '\0';i++)
{
if (isNumber(str))
{
n = str - '0';
if (isNumber(str[i + 1]))
{
i++;
n = n * 10 + str - '0';
}
s->push(n);
}
else
{
if (str == '+')
{
i++;
n = str - '0';
if (isNumber(str[i + 1]))
{
i++;
n = n * 10 + str - '0';
}
n += s->pop();
s->push(n);
}
}
}
n = 1;
for (int j = 0;j < s->point;j++)
{
n *= s->data[j];
}
delete s;
return n;
}
int min(char str[128])
{
long long n = 0;
Stack *s = new Stack();
for (int i = 0;str != '\0';i++)
{
if (isNumber(str))
{
n = str - '0';
if (isNumber(str[i + 1]))
{
i++;
n = n * 10 + str[i] - '0';
}
s->push(n);
}
else
{
if (str[i] == '*')
{
i++;
n = str[i] - '0';
if (isNumber(str[i + 1]))
{
i++;
n = n * 10 + str[i] - '0';
}
n *= s->pop();
s->push(n);
}
}
}
n = 0;
for (int j = 0;j < s->point;j++)
{
n += s->data[j];
}
delete s;
return n;
}

int main()
{
int n;
char str[128] = "";
cin >> n;
cin.getline(str,128);
while(n--)
{
cin.getline(str,128);
cout << "The maximum and minimum are " << max(str) << " and " << min(str) << '.' << endl;
}
return 0;
}[/cpp]
Last edited by Morning on Sat Sep 25, 2004 7:01 pm, edited 1 time in total.
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

Junayeed
New poster
Posts: 50
Joined: Sat Oct 26, 2002 9:02 am
Location: Dhaka, Bangladesh

Post by Junayeed » Sat Sep 25, 2004 6:05 pm

Try this i/p

20*20*20*20*20*20*20*20*20*20*20*20

Hope this will help
Junayeed

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

Post by Morning » Sat Sep 25, 2004 7:05 pm

yeah,stupid mistake
thanks so much,buddy:)
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

phoenixKonquerer
New poster
Posts: 3
Joined: Thu Mar 17, 2005 3:13 pm

10700 test data

Post by phoenixKonquerer » Thu Mar 17, 2005 3:17 pm

Hello there, I got WA for question 00 for volume 107.

Is there anyone out there with AC to this problem and if yes can you please supply me with some testing input data along with the correct answer to it please.

Thank you so much. :lol:

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Thu Mar 17, 2005 3:32 pm

My solution was simply to swap the priority of operators '+' and '*'. Perhaps you're getting WA if you don't use 64-bit integers

Consider this case:
20*20*20*20*20*20*20*20*20*20*20*20

phoenixKonquerer
New poster
Posts: 3
Joined: Thu Mar 17, 2005 3:13 pm

Re: Camel Trading WA

Post by phoenixKonquerer » Fri Mar 18, 2005 2:22 pm

Hello I took ur advise and change my int variables to unsigned long long variables but I still got a WA for my submission.

The answer to ur example is

4096000000000000

Do u have any more testing data ?

Thanks for your help.

Dmytro Chernysh
Experienced poster
Posts: 146
Joined: Sat Apr 26, 2003 2:51 am

Post by Dmytro Chernysh » Wed Apr 06, 2005 12:41 am

Yep, indeed, the answers are
The maximum and minimum are 4096000000000000 and 4096000000000000.

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Sat Jun 04, 2005 11:50 am

Junayeed,
you told that your previous output was right

which was

input

Code: Select all

20*20*20*20 

output

Code: Select all

160000 and 0.
how the "0" comes for the minimum
i think Junayeed was wrong
can anyone explain[/quote]
Last edited by emotional blind on Sun Mar 16, 2008 10:07 am, edited 1 time in total.

Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman » Sat Jun 04, 2005 1:54 pm

The output should be 160000 and 160000 according to my AC program.
You should never take more than you give in the circle of life.

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Sat Jun 11, 2005 8:27 am

thanks a lot

sunny
Experienced poster
Posts: 124
Joined: Sun Sep 11, 2005 10:22 pm
Location: Civil-BUET

10700 - can't find mistake

Post by sunny » Thu Oct 13, 2005 3:14 pm

i don't know for what input my program fails to output correctly.
i considered the case where all 12 numbers are 20. any1 pls debug my code.


[ Code removed By Moderator ]

User avatar
Tanu
Learning poster
Posts: 70
Joined: Sun May 29, 2005 12:46 pm
Location: Mars

10700 sampl input-output??

Post by Tanu » Thu Nov 24, 2005 3:51 pm

plz give me some sample input-output for problem 10700
http://acm.uva.es/p/v107/10700.html
I don't forgot to use long long data type...
Thanks in advance...
Tan

User avatar
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

i/o for 10700

Post by Rocky » Thu Nov 24, 2005 3:55 pm

what ouput does you get for this input
1
20*20*20*20*20*20*20*20*20*20*20*20

GOOD LUCK
Rocky

User avatar
Tanu
Learning poster
Posts: 70
Joined: Sun May 29, 2005 12:46 pm
Location: Mars

Thanks

Post by Tanu » Mon Nov 28, 2005 2:29 pm

Yah i got it accepted...
Thanx

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

Re: 10700 - can't find mistake

Post by Martin Macko » Sat Dec 10, 2005 11:17 pm

sunny wrote:printf("The maximum and minimum are %.0Lf and %.0Lf\n",max,min);
You forgot "." at the end of the output sentence.

In future, please, put your code to

Code: Select all

 tags.

Post Reply

Return to “Volume 107 (10700-10799)”