Under construction

Still being built. Things may change

User Names

Time limit3sMemory limit256 MB

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

  1. A user name is at most MAXLEN characters long. The value of MAXLEN is given in the input for each test case.
  2. 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.
  3. Append as many letters of the person's last name as possible (converted to lower case) without making the user name longer than MAXLEN characters. Start from the first letter of the last name and append the letters in the order they appear.
  4. 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 exceed MAXLEN characters. If appending a single digit would exceed MAXLEN, drop the last letter before appending the serial number.
  5. 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 exceed MAXLEN characters. If appending two digits would exceed MAXLEN, drop the last letter, or the last two letters, as needed, before appending the serial number.
  6. 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 (5≤MAXLEN≤805 \le \text{MAXLEN} \le 80). 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.

Examples1

  1. Example 1

    Input
    2 6
    Jenny Ax
    Christos H Papadimitriou
    11 8 
    Jean-Marie d'Arboux
    Jean-Marie A d'Arboux
    Jean-Marie B d'Arboux
    Jean-Marie C d'Arboux
    Jean-Marie D d'Arboux
    Jean-Marie D d'Arboux
    Jean-Marie F d'Arboux
    Jean-Marie G d'Arboux
    Jean-Marie H d'Arboux
    Jean-Marie I d'Arboux
    Jean-Marie J d'Arboux
    11 9 
    Jean-Marie d'Arboux
    Jean-Marie A d'Arboux
    Jean-Marie B d'Arboux
    Jean-Marie C d'Arboux
    Jean-Marie D d'Arboux
    Jean-Marie D d'Arboux
    Jean-Marie F d'Arboux
    Jean-Marie G d'Arboux
    Jean-Marie H d'Arboux
    Jean-Marie I d'Arboux
    Jean-Marie J d'Arboux
    0 0
    
    Expected output
    Case 1
    jax
    cpapad
    Case 2
    jdarboux
    jdarbou1
    jdarbou2
    jdarbou3
    jdarbou4
    jdarbou5
    jdarbou6
    jdarbou7
    jdarbou8
    jdarbou9
    jdarbo10
    Case 3
    jdarboux
    jdarboux1
    jdarboux2
    jdarboux3
    jdarboux4
    jdarboux5
    jdarboux6
    jdarboux7
    jdarboux8
    jdarboux9
    jdarbou10