UserName
SRM 203 · 2004-07-15 · by Eeyore
Problem Statement
You are implementing the member registration system of an online dating site. When a new member signs up, it is possible that she initially chooses the same username as an existing member. The system must then inform the new member of the conflict and suggest a variant of the chosen name with a number attached to the end.
If an existing member is named "FunkyMonkey", for example, and a new member wants the same username, the simplest suggestion the system can make is "FunkyMonkey1". If there is already a member by that name, the system must suggest "FunkyMonkey2", unless that variant is also taken. If all names from "FunkyMonkey1" through "FunkyMonkey9" are taken as well as the original "FunkyMonkey", the system moves on to consider "FunkyMonkey10", and so on. The goal is to use the smallest possible number in the variant. Note that each username consists of letters (the characters from 'a' to 'z' and from 'A' to 'Z') and numerals ('0' to '9').
You are given a
Notes
- The constraints rule out names that end in a number with a leading zero, such as "grokster006" and "bart0".
Constraints
- existingNames contains between 1 and 50 elements, inclusive
- each element of existingNames is between 1 and 50 characters long, inclusive
- the only characters permitted in elements of existingNames are 'a' to 'z', 'A' to 'Z', and '0' to '9'
- no element of existingNames ends in a number that has a leading zero
- newName is between 1 and 50 characters long, inclusive
- the only characters permitted in newName are 'a' to 'z' and 'A' to 'Z'
{"MasterOfDisaster", "DingBat", "Orpheus", "WolfMan", "MrKnowItAll"}
"TygerTyger"
Returns: "TygerTyger"
"TygerTyger" is available.
{"MasterOfDisaster", "TygerTyger1", "DingBat", "Orpheus",
"TygerTyger", "WolfMan", "MrKnowItAll"}
"TygerTyger"
Returns: "TygerTyger2"
"TygerTyger" and "TygerTyger1" are taken.
{"TygerTyger2000", "TygerTyger1", "MasterDisaster", "DingBat",
"Orpheus", "WolfMan", "MrKnowItAll"}
"TygerTyger"
Returns: "TygerTyger"
There are higher-numbered variants of "TygerTyger", but the base name is available.
{"grokster2", "BrownEyedBoy", "Yoop", "BlueEyedGirl",
"grokster", "Elemental", "NightShade", "Grokster1"}
"grokster"
Returns: "grokster1"
Note that "Grokster1" is not the same as "grokster1".
{"Bart4", "Bart5", "Bart6", "Bart7", "Bart8", "Bart9", "Bart10",
"Lisa", "Marge", "Homer", "Bart", "Bart1", "Bart2", "Bart3",
"Bart11", "Bart12"}
"Bart"
Returns: "Bart13"
Submissions are judged against all 56 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class UserName with a public method string newMember(vector<string> existingNames, string newName) · 56 test cases · 2 s / 256 MB per case