StreamKid
January 25th, 2007, 06:36 AM
i have to choose between some eggs. at the end, i have to output the solution in a specific way. each egg has two numbers: its size and its number in the sequence of all the eggs i have (ie i have 10 eggs, and i chose the 10nth).
when i select more than one egg, as a solution, i have to print the sequence-number of the eggs, but according to the size of each egg.
example: i have 4 eggs:
egg1 has a size of 4kg, egg2 has a size of 2kg, egg3 a size of 3kg and egg4 a size of 7kg.
suppose i 've chosen eggs 1, 2, 4.
we have (according to size) that egg4> egg1 > egg2 so i have to print first the number of egg4( 4 ), then the egg1 (1) and then egg2( 2). thus, correct solution: 4, 1, 2
to solve this, i thought of using a container where each record has a key and a value. at the first container i create, i will store each egg as i found it. egg1: a record with key 1, and value the size of the 1st egg. egg2: a record with key 2 and value the size of the 2nd key. and so on. when i later chose my eggs, i go to this container, i found the eggs i 've chosen, and i find which is bigger so i print them in a correct way...
i _tried_ to implement this in c++, but i don't think i did it correct...
i can post code if anyone wants...
does anybody have another algo to suggest or any comment to do in this???
when i select more than one egg, as a solution, i have to print the sequence-number of the eggs, but according to the size of each egg.
example: i have 4 eggs:
egg1 has a size of 4kg, egg2 has a size of 2kg, egg3 a size of 3kg and egg4 a size of 7kg.
suppose i 've chosen eggs 1, 2, 4.
we have (according to size) that egg4> egg1 > egg2 so i have to print first the number of egg4( 4 ), then the egg1 (1) and then egg2( 2). thus, correct solution: 4, 1, 2
to solve this, i thought of using a container where each record has a key and a value. at the first container i create, i will store each egg as i found it. egg1: a record with key 1, and value the size of the 1st egg. egg2: a record with key 2 and value the size of the 2nd key. and so on. when i later chose my eggs, i go to this container, i found the eggs i 've chosen, and i find which is bigger so i print them in a correct way...
i _tried_ to implement this in c++, but i don't think i did it correct...
i can post code if anyone wants...
does anybody have another algo to suggest or any comment to do in this???