Page 1 of 2
330 - Inventory Maintenance
Posted: Thu May 09, 2002 3:04 pm
by jpfarias
Hi!
Can anyone tell me if there's any trick in this problem?
Should I report itens with qtd = 0?
Should I use blanks in the output to fill the row?
I'm getting WA and don't know why...
Sample input/output will be good for me too.

Help needed...
Posted: Tue May 21, 2002 1:46 pm
by jpfarias
Can anyone tell me if my output for this input is ok?
Input:
new test
0.5 1.5
buy test 20
sell test 10
delete test
report
*
Output:
INVENTORY REPORT
Item Name Buy At Sell At On Hand Value
--------- ------ ------- ------- -----
------------------------
Total value of inventory 0.00
Profit since last report 5.00
Thanx in advance...
P330
Posted: Wed May 22, 2002 5:29 am
by Fresh
My accepted program said as below, seem similar to yours.
[c]
INVENTORY REPORT
Item Name Buy At Sell At On Hand Value
--------- ------ ------- ------- -----
------------------------
Total value of inventory 0.00
Profit since last report 5.00
[/c]
-novice

Can help me anymore?
Posted: Thu May 23, 2002 3:13 pm
by jpfarias
Hi!
Can u send me input / output to this problem?
Thanx in advance!
Jo
330 - Inventory Maintance
Posted: Thu Jan 16, 2003 2:49 pm
by Dominik Michniewski
Could anyone tell me some special cases for this problem ?
I think, that I check all of them, but maybe I miss something .... I don't want to post code there, because it's quite big

(ca. 4kB)
Maybe I misunderstand problem description

?
Best regards
Dominik
PS. If someone would get my code -> send me private message

maybe this person should help me

Posted: Tue Jan 21, 2003 4:07 pm
by little joey
As always: "when you have eliminated the impossible whatever remains, however improbable , must be the truth". So in this case, when you have tried all probable testcases, and you still get WA, you will have to suspect that the problem description is wrong.
It says:
new item-name item-cost item-selling-price
This line adds a new item (not previously carried in the store) to the potential inventory.
And also:
and Madam Phoenix guarantees you that there will be no errors in the input
Which would make the following input illegal:
Code: Select all
new test 0.5 1.5
buy test 20
sell test 10
report
delete test
new test 0.5 1.0
buy test 20
sell test 10
report
*
Have you guessed it already?
The first quote should read:
new item-name item-cost item-selling-price
This line adds a new item (not currently carried in the store) to the potential inventory.
Many lonely hours of feverish debugging are the result of these errors. But hey, consider them part of the problem (which I now have spoiled

).
Posted: Wed Jan 22, 2003 9:01 am
by Dominik Michniewski
So that means .... that your part of input could be properly ?
So I think, that my program could have only problem with input like this:
Code: Select all
new item1 0.1 0.2
buy item1 10
sell item1 5
new item1 0.1 0.2
because I don't check if new item exist in store

Try to modify my code and sen it OJ
But What can I do in this case ? modify sell/buy parameter of item ? last is correct? how can I calculate profit in this case ?
Thanks for help
Dominik
Posted: Wed Jan 22, 2003 10:08 am
by little joey
Well, within my twenty or so submissions I verified that:
- No items are sold, bought or deleted if their status is 'deleted'.
- There can be mutiple new commands for the same item, but only if the status of that item is 'deleted' at the time of the recurring new command.
The sequence NEW,{BUY|SELL},DELETE,NEW,... is legal, but the following are not:
NEW,{BUY|SELL},NEW,...
NEW,{BUY|SELL},DELETE,(BUY|SELL|DELETE)...
This all seems logical when you replace the word 'previously' by 'currently'.
Once you accept this fact, the rest follows from it. I'm not going to tell you what happens to the buy,sell and profit numbers; it's easy to figure that out.
Posted: Wed Jan 22, 2003 10:15 am
by Dominik Michniewski
Could I send you my code ? maybe you find any mistakes in my code ....
Dominik Michniewski
PS. In mean time I check how my program behave with your input

Posted: Wed Jan 22, 2003 10:35 am
by little joey
Sorry, the legal sequence should read:
NEW,{(BUY),{BUY|SELL}},[(DELETE)|{(DELETE,NEW,{(BUY),{BUY|SELL}})}]
where the number of sold items never exeeds the number of bought items, and the judge's data conforms to this (AFAIK).
PS. Shure you can send your code.
Posted: Sat Feb 07, 2004 7:43 pm
by sjn
Sometime the judge gives WA instead of RTE
so Dominik Michniewski, you may not got WA but RTE
hope useful

Posted: Sun Feb 08, 2004 4:13 pm
by junbin
Actually, I think the test data is wrong... I sent the following code in and it gave me SIGFPE (floating point error, division by zero).
The program below will not print anything. It will go into an infinite loop if there isn't at least one line that has '*' as the starting character (terminating condition). It will give SIGFPE if there is a command to add an item which already exists or if there is a command to delete an item that does NOT exist.
[cpp]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char items[100][20];
int iused[100];
int main(void) {
char buff[10000];
char *p, *q;
int i;
memset(iused, 0, sizeof(iused));
memset(items, 0, sizeof(items));
while (gets(buff)) {
if (*buff == '*') { break; }
if (strncmp(buff, "new", 3) == 0) {
p = buff + 3;
while (*p == ' ') { p++; }
q = p;
while (*q && *q != ' ') { q++; }
*q = 0;
for (i = 0; i < 100; i++) {
if (iused) {
// Crash if item already exists (not unique)
if (!strcmp(items, p)) { i = 1 / (i ^ i); }
}
}
for (i = 0; i < 100; i++) {
if (!iused) {
strcpy(items, p);
iused = 1;
break;
}
}
} else if (strncmp(buff, "delete", 6) == 0) {
p = buff + 6;
while (*p == ' ') { p++; }
q = p;
while (*q && *q != ' ') { q++; }
*q = 0;
for (i = 0; i < 100; i++) {
if (iused) {
if (!strcmp(items, p)) {
iused = 0;
break;
}
}
}
// Crash if item does not exist (no item to delete)
if (i == 100) { i = 1 / (i ^ i); }
}
}
while (*buff != '*') {
*(buff+1) = 2;
}
return 0;
}
[/cpp]
Posted: Sun Feb 08, 2004 4:49 pm
by junbin
Can I check if anyone has solved this question within the last few days?
All my code got rejected as output limit exceeded. When I tried to check, I find that the judge's test data asks for over 500 "report"'s... which will very likely in itself be a very large output.
Did I miss something or is the judge wrongly configured somehow?
Posted: Sun Feb 08, 2004 5:43 pm
by little joey
I just re-submitted my previously accepted solution to the judge and it got accepted again.
There's nothing wrong with the judge or it's data

Posted: Mon Feb 09, 2004 10:35 am
by Dominik Michniewski
Maybe I got RTE, but I think, that I check all incorrect situations

maybe I miss something, but I still think that I must have a mistake in code (but I don't know when). If anyone can help me, I would be greatful ...
Best regards
DM