Create the username portion of a registration system that requires all usernames are unique. If a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create the username portion of a registration system that requires all usernames are unique. If a new user requests a name that is already used, an integer should be added to the end of the username to make it unique. The numbering begins with 1 and is incremented by 1 for each new instance per username. As an example, if username requests were for [bob, alice, bob, alice, bob, alice], the system should assign usernames [bob, alice, bob1, alice1, bob2, alice2]. Given a list of username requests in the order given, process all requests and return an array of the usernames as assigned by the function. Function Description Complete the function usernamesSystem in the editor below. The function must return an array of usernames in the order assigned. usernamesSystem has the following parameter(s): u[u[0]....u[n-1]]: an array of username strings in the order requested Constraints 1≤n≤ 104 1 ≤ lu[i] ≤ 20 u[i] contains only lowercase English letters in the range ascii[a-z]. ▾ Input Format for Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains n, the number of strings in array u. The next n lines each contain a string u[i] representing a username request in the order received. ▾ Sample Case 0 Sample Input 4 alex xy los alex alan Sample Output 0 alex xylos alex1 alan Explanation 0 There are 4 usernames requested. Each username is unique with the exception of "alex": u[2] = "alex" must be modified. Since this is the first duplicate request for the username "alex", the function should insert "alex1" to that position in u. ▾ Sample Case 1 Sample Input 2 bob alice Sample Output 1 bob alice Explanation 1 Each of the users has a different username so no modifications are needed. Explanation 1 Each of the users has a different username so no modifications are needed. ▾ Sample Case 2 Sample Input 4 john john tom john Sample Output 2 john john1 tom john2 Explanation 2 Three instances of "john" require that usernames "john", "john1" and "john2" be inserted into the array at the appropriate positions. 1 'use strict'; 26 /* 27 28 29 30 31 32 33 34 35 * Complete the 'usernames System' function below. * The function is expected to return a STRING_ARRAY. * The function accepts STRING_ARRAY u as parameter. */ function usernames System (u) { // Write your code here Create the username portion of a registration system that requires all usernames are unique. If a new user requests a name that is already used, an integer should be added to the end of the username to make it unique. The numbering begins with 1 and is incremented by 1 for each new instance per username. As an example, if username requests were for [bob, alice, bob, alice, bob, alice], the system should assign usernames [bob, alice, bob1, alice1, bob2, alice2]. Given a list of username requests in the order given, process all requests and return an array of the usernames as assigned by the function. Function Description Complete the function usernamesSystem in the editor below. The function must return an array of usernames in the order assigned. usernamesSystem has the following parameter(s): u[u[0]....u[n-1]]: an array of username strings in the order requested Constraints 1≤n≤ 104 1 ≤ lu[i] ≤ 20 u[i] contains only lowercase English letters in the range ascii[a-z]. ▾ Input Format for Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains n, the number of strings in array u. The next n lines each contain a string u[i] representing a username request in the order received. ▾ Sample Case 0 Sample Input 4 alex xy los alex alan Sample Output 0 alex xylos alex1 alan Explanation 0 There are 4 usernames requested. Each username is unique with the exception of "alex": u[2] = "alex" must be modified. Since this is the first duplicate request for the username "alex", the function should insert "alex1" to that position in u. ▾ Sample Case 1 Sample Input 2 bob alice Sample Output 1 bob alice Explanation 1 Each of the users has a different username so no modifications are needed. Explanation 1 Each of the users has a different username so no modifications are needed. ▾ Sample Case 2 Sample Input 4 john john tom john Sample Output 2 john john1 tom john2 Explanation 2 Three instances of "john" require that usernames "john", "john1" and "john2" be inserted into the array at the appropriate positions. 1 'use strict'; 26 /* 27 28 29 30 31 32 33 34 35 * Complete the 'usernames System' function below. * The function is expected to return a STRING_ARRAY. * The function accepts STRING_ARRAY u as parameter. */ function usernames System (u) { // Write your code here
Expert Answer:
Answer rating: 100% (QA)
Code include include using namespace std define MAXCHAR 26 struct additional bool is int add ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
The FOREIGN KEY constraint should be added to which table? a. The table representing the "one" side of a one-to-many relationship b. The parent table in a parent-child relationship c. The child table...
-
What amount of energy should be added to an electron to reduce its de Broglie wavelength from 100 to 50 pm?
-
Do you think additional federal lands should be added to the wilderness system? Why or why not?
-
In Exercises 7192, find and simplify the difference quotient f(x +h)-f(x) h -, h = 0
-
Use the data for Cranwell Company in E6-18A to answer the following. May 1 Beginning inventoryl ........................... 6 units $150 = $ 900 15 Purchase...
-
Briefly define each of the following: a. Distribution of sample means b. Expected value of M c. Standard error of M
-
T. Christian Cooper was a partner to Sanders and Richard Campbell d/b/a The Mullen Company. In 2001, Cooper helped bring about a management agreement between The Mullen Co. and Newnan Crossing...
-
Direct labor variances: price, efficiency, mix, and yield. Trevor Joseph employs two workers in his guitar-making business. The first worker, George, has been making guitars for 20 years and is paid...
-
Seri Minyak Bhd uses crude palm oil in producing its products. The company expected to use 200 tonnes of crude palm oil in July 2023 to meet the demand in the festival season. If the price of raw...
-
A survey of families living in a certain city was conducted to collect information on the following variables: age of the oldest person in the family, number of family members, number of males in the...
-
A pyrotechnician releases a 3 kg firecracker from rest. At t = 0.4 s the firecracker is moving downward with speed 4, when it begins to explode into two pieces with masses m top = 1 kg and mbottom 2...
-
Textbook publishers face growing competition on numerous fronts, including new models of textbook delivery. One such model provides students with online textbook content for free, on the condition...
-
What forms can strategic alliances take?
-
Assume that in 2019, the following prevails in the Republic of Nurd: Assume that households consume 80 percent of their income, they save 20 percent of their income, MPC = 0.8, and MPS = 0.2. That...
-
How has the practice of corporate strategy evolved over time?
-
What is the role of luck in gaining possession of a particular resource or capability? Can a firm manage luck? Give an example of a resource or capability that a firm garnered through luck and...
-
27-34 Calculate, to four decimal places, the first eight terms of the recursive sequence. Does it appear to be convergent? If so, guess the value of the limit. Then assume the limit exists and...
-
One study found that the elderly who do not have children dissave at about the same rate as the elderly who do have children. What might this finding imply about the reason the elderly do not dissave...
-
When is creating an index manually inappropriate? a. When queries return a large percentage of rows in the results b. When the table is small c. When the majority of table operations are updates d....
-
Which of the following isnota valid SQL statement? a. SELECT MIN (pubdate) FROM books GROUP BY category HAVING pubid = 4; b. SELECT MIN (pubdate) FROM books WHERE category = 'COOKING'; c. SELECT...
-
Which of the following represents exactly one character in a pattern search? a. ESCAPE b. ? c. d. % e. None of the above
-
An economy is described by the following equations: Desired consumption \(C^{d}=300+0.5(Y-T)-300 r\). Desired investment \(\quad I^{d}=100-100 r\). Government purchases \(\quad G=100\). Taxes...
-
Describe three alternative responses available to policymakers when the economy is in recession. What are the advantages and disadvantages of each strategy? Be sure to discuss the effects on...
-
How do the assumptions of prices in the Keynesian and classical models have different implications on monetary policy?
Study smarter with the SolutionInn App