CS Proficiency Exam September 6 , 2008

advertisement
CS Proficiency Exam
September 6th, 2008
Given a file inventory.txt with inventory information for an appliance store. Each line in
the file contains the ID number of an appliance and the number of these appliances in
stock (that means, the number of appliances in the warehouse). The file is sorted by ID
numbers and does not contain more than 50 appliances. Also given a file sold.txt with
information about appliances sold. Each line in the file sold.txt contains the ID number of
an appliance sold. The same ID number may be in the file several times. All the ID
numbers in sold.txt are also in inventory.txt. There is no limit on the number of lines in
sold.txt. Your program must determine how many of each appliance to reorder using the
following guidelines:
• For each appliance which is sold out (0 appliances in stock), re-order 20% more items
than were sold, but at least 2 more.
• For each appliance which was not sold at all, re-order no items.
• For each appliance which was sold but is still in stock, re-order 20% less than was
sold, but at least 1 less. Except, if this would mean that 0 items are re-ordered, then
re-order at least one item.
Round the items to be re-ordered to the nearest integer.
Your program must print out the total number of items sold and the total number of items
to be re-ordered. This is followed by a list (sorted by ID number) the number of items to
re-order (together with their ID number). Do not print out an appliance for which 0 items
must be re-ordered. Your program must also print out the ID numbers and the number of
items sold, sorted by the number of items sold. If there is a tie, use the ID number to
break it.
There is at least one blank space between the ID number and the items in stock in the file
inventory.txt.
Example:
inventory.txt
sold.txt
3
40
3
6
6
29
11
0
29
29
8
11
41
3
41
11
11
Output:
Total number of items sold: 7
Total number of times to re-order:
Sorted list of items to re-order:
3 1
11 5
29
41
1
1
Sorted list of items sold:
11 3
29 2
3 1
41 1
Download