330 - Inventory Maintenance

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

Moderator: Board moderators

jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

330 - Inventory Maintenance

Post by jpfarias » Thu May 09, 2002 3:04 pm

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. :-?

jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

Help needed...

Post by jpfarias » Tue May 21, 2002 1:46 pm

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...

Fresh
New poster
Posts: 46
Joined: Mon Apr 15, 2002 10:42 am
Contact:

P330

Post by Fresh » Wed May 22, 2002 5:29 am

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 :roll:

jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

Can help me anymore?

Post by jpfarias » Thu May 23, 2002 3:13 pm

Hi!

Can u send me input / output to this problem?

Thanx in advance!

Jo

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

330 - Inventory Maintance

Post by Dominik Michniewski » Thu Jan 16, 2003 2:49 pm

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 :)

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

Post by little joey » Tue Jan 21, 2003 4:07 pm

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 8) ).

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Wed Jan 22, 2003 9:01 am

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

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

Post by little joey » Wed Jan 22, 2003 10:08 am

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.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Wed Jan 22, 2003 10:15 am

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 :)

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

Post by little joey » Wed Jan 22, 2003 10:35 am

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.

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

Post by sjn » Sat Feb 07, 2004 7:43 pm

Sometime the judge gives WA instead of RTE
so Dominik Michniewski, you may not got WA but RTE

hope useful :wink:

junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am

Post by junbin » Sun Feb 08, 2004 4:13 pm

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]

junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am

Post by junbin » Sun Feb 08, 2004 4:49 pm

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?

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

Post by little joey » Sun Feb 08, 2004 5:43 pm

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 :)

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Mon Feb 09, 2004 10:35 am

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
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Post Reply

Return to “Volume 3 (300-399)”