User Names
Time limit3sMemory limit256 MB
Generate unique lowercase user names from full names using fixed truncation and numeric suffix collision rules, printing each result.
- Level
Medium4 of 10
- Topics
- String, Hash map, Simulation, Implementation
- Solved
- No attempts yet
Problem
A university's computer system assigns each person a user name using the following rules.
- A user name is at most
MAXLENcharacters long. The value ofMAXLENis given in the input for each test case. - The first character of the user name is the first letter of the person's first name, converted to lower case. Apostrophes and hyphens are ignored here and in Rule 3.
- Append as many letters of the person's last name as possible (converted to lower case) without making the user name longer than
MAXLENcharacters. Start from the first letter of the last name and append the letters in the order they appear. - If the user name produced by Rules 1–3 already exists in the database, resolve the collision by appending the serial numbers
1–9, in that order, to the user name from Rule 3, as long as the result does not exceedMAXLENcharacters. If appending a single digit would exceedMAXLEN, drop the last letter before appending the serial number. - If the user name produced by Rules 1–4 already exists in the database, resolve the collision by appending the serial numbers
10–99, in that order, to the user name from Rule 3, as long as the result does not exceedMAXLENcharacters. If appending two digits would exceedMAXLEN, drop the last letter, or the last two letters, as needed, before appending the serial number. - You may assume that these rules are always enough to avoid collisions.
Input
The input contains several test cases. The first line of each test case contains two positive integers: the number of names and the value of MAXLEN (). The list of names follows.
Each name is at most 80 characters long. It begins with the first name, is followed by middle names (if any), and ends with the last name; a single space separates consecutive parts. A name may contain upper- and lower-case letters, hyphens, and apostrophes. The last name has at least two letters; every other part has at least one letter (some parts may be just initials). Each test case has at most 200 names.
The last test case is followed by a line containing two zeros (the number of names and MAXLEN), which is not processed.
Output
For each test case, first print a line with the case number in the form Case k (where k starts at 1). Then print the generated user names, one per line, in the same order as the corresponding names in the input.