Ali is stuck with a database assignment, can you help him?
The assignment states that you are to design a code for a registration system that goes as follows:
Each time a new user wants to register, he sends to the system a request with his name.
The first line of input contains an integer $n$ $(1 \le n \le 10^5)$ --- the number of requests.
Then the following $n$ lines contain a string $s$ ($1 \le |s| \le 20)$ --- $s$ contains lowercase english letters and numbers.
print $n$ lines, $i$th line describes the response for name $i$.
Input | Output |
---|---|
5 ali ali2 ali ali ali1 Copy
|
ok ok ali1 ali3 ali11 Copy
|
We need to Keep track of the numbers in the suffix of each name.
example: name = "a12"
from this name I need to know that "a1" has a suffix equal to 2, also, I need to know that "a" has a suffix equal to 12.
we can do this using a a map<string, set>, for each string we will add its suffix (eg: have["a1"].insert(2), have["a"].insert(12))
now for each request, I need to get the minimum $i$ that does not exist in have[name].