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
-
Index funds are mutual funds that try to mimic the movement of leading indexes, such as the S&P 500 or the Russell 2000. The beta values (as described in Problem 13.49) for these funds are therefore...
-
For each of the five "boxes" on the outside of the AFI circle (above), explain the concrete steps you take as a top management team to accomplish those between rounds (e.g., assess previous round...
-
The 2015 annual report of the Procter & Gamble Company (P&G) is available at www.pginvestor.com. After reviewing P&Gs annual report, respond to the following questions: a. How does P&G value its...
-
The December 31, 2014 balance sheet of Myers and Myers, prepared under generally accepted accounting principles, follows. (This problem requires knowledge of present value calculations. Refer to...
-
In an effort to increase profits, Pegasus Airlines is thinking about dropping several flights that appear to be unprofitable. A typical income statement for one round - trip of one such flight (...
-
Consider an individual whose preferences are defined over bundles of non-negative amounts of each of two commodities. Suppose that this individual's preferences can be represented by a utility...
-
97. Convert the boiling temperature of liquid ammonia, -28.1 F, into degrees Celsius and kelvin.
-
During 2005 , Liberty's days' sales in receivables ratio was a. 39 day's b. 37 day's c. 35 day's d. 30 days
-
Liberty's inventory turnover during 2007 was a. 6 times b. 7 times c. 8 times d. Not determinable from the data given
-
Liberty's stock has traded recently around \(\$ 44\) per share. Use your answer to question 9 to measure the company's price/earnings ratio. a. 36 b. 44 c. 1.00 d. 69
-
Triumph Corporation is preparing its statement of cash flows by the indirect method. Triumph has the following items for you to consider in preparing the statement. Identify each item as an -...
-
Anita Maxwell Company expects the following for 2007: Net cash provided by operating activities of $150,000 Net cash provided by financing activities of $60,000 Net cash used for investing...
-
what measures will use for the document in question . Recall that "measures" are quantifiable indicators, or proxies, Measure (independent variable 1) and source? Measure (independent variable 2) and...
-
7. FALSE DILEMMA 8. GANDWAGON Definition: Fallacy example: How to revise argument: Definition: Fallacy example: How to revise argument:
-
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
-
Choose letter \(\mathrm{C}\) (for committed fixed cost) or \(\mathrm{D}\) (for discretionary fixed cost) to indicate the type of each of the following described costs. a. Professional meeting...
-
The following data are from a recent General Electric Company annual report. All amounts, except per share data, are in \(\$\) millions. Required Compute the following ratios for the General Electric...
-
For each description of a cost change in items a through \(g\), indicate whether the cause is due to (1) underlying cost behavior, (2) inflation or deflation, (3) supply or supplier cost adjustments,...
Study smarter with the SolutionInn App