SantaGifts
SRM 331 · 2006-12-21 · by slex
Problem Statement
Santa Claus has come with a bag full of presents this year. A group of N kids stand in line, anxious to get their gifts. Santa Claus takes a present from his bag and gives it to the kid who is currently first in line. That kid then goes to the end of the line, unless he already has 4 gifts, in which case, he goes home. This process continues as long as there are presents in the bag and kids in the line.
You are given a
Constraints
- gifts will contain between 1 and 50 elements, inclusive.
- Each element of gifts will contain between 1 and 10 lowercase letters ('a'-'z'), inclusive.
- N will be between 1 and 50, inclusive.
{"ball","plane","robot","puzzle"}
3
Returns: {"ball puzzle", "plane", "robot" }
The first kid gets a ball, the second one a plane, and the third one a robot. Then the first kid reaches the front of the line again and gets the last gift.
{"ball","plane","robot","puzzle","bike"}
1
Returns: {"ball plane robot puzzle" }
There is only one kid, so he will take the first four presents.
{"ball","ball","plane","plane"}
2
Returns: {"ball plane", "ball plane" }
In this case Santa Claus is fair and gives a ball and a plane to both kids.
{"ball","plane","robot"}
5
Returns: {"ball", "plane", "robot", "", "" }
Unfortunately, not all the kids will get gifts.
{"dsoggb","zep","ldxkwwjg","erkbrzb","jrrmwxcbzk","noihltl","jhdq","orvustvqqr","nyliepmu","shko","bwc","fwfnjkw"}
33
Returns: {"dsoggb", "zep", "ldxkwwjg", "erkbrzb", "jrrmwxcbzk", "noihltl", "jhdq", "orvustvqqr", "nyliepmu", "shko", "bwc", "fwfnjkw", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
Submissions are judged against all 68 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SantaGifts with a public method vector<string> distribute(vector<string> gifts, int N) · 68 test cases · 2 s / 256 MB per case