10700 - Camel trading
Moderator: Board moderators
10700 Why WA???
[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]
#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
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
-
- New poster
- Posts: 3
- Joined: Thu Mar 17, 2005 3:13 pm
10700 test data
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.
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.

-
- New poster
- Posts: 3
- Joined: Thu Mar 17, 2005 3:13 pm
Re: Camel Trading WA
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.
The answer to ur example is
4096000000000000
Do u have any more testing data ?
Thanks for your help.
-
- Experienced poster
- Posts: 146
- Joined: Sat Apr 26, 2003 2:51 am
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Junayeed,
you told that your previous output was right
which was
input
output
how the "0" comes for the minimum
i think Junayeed was wrong
can anyone explain[/quote]
you told that your previous output was right
which was
input
Code: Select all
20*20*20*20
Code: Select all
160000 and 0.
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.
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
10700 - can't find mistake
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 ]
i considered the case where all 12 numbers are 20. any1 pls debug my code.
[ Code removed By Moderator ]
10700 sampl input-output??
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
http://acm.uva.es/p/v107/10700.html
I don't forgot to use long long data type...
Thanks in advance...
Tan
i/o for 10700
what ouput does you get for this input
1
20*20*20*20*20*20*20*20*20*20*20*20
GOOD LUCK
Rocky
1
20*20*20*20*20*20*20*20*20*20*20*20
GOOD LUCK
Rocky
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: 10700 - can't find mistake
You forgot "." at the end of the output sentence.sunny wrote:printf("The maximum and minimum are %.0Lf and %.0Lf\n",max,min);
In future, please, put your code to
Code: Select all
tags.