Write a function: string solution (string &S, string &T); that, given two strings S and T...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function: string solution (string &S, string &T); that, given two strings S and T consisting of N and M characters, respectively, determines whether string T can be obtained from string S by at most one simple operation from the set specified below. The function should return a string: • "INSERT c" if string T can be obtained from string S by inserting a single character "c" at the beginning of the string; • "REMOVE c" if string T can be obtained from string S by deleting a single character "c" from the end of the string; • "SWAP c d" if string T can be obtained from string S by swapping two adjacent characters "c" and "d" (these characters should be distinct and in the same order as in string S; exactly one swap is performed); "EQUAL" if no operation is needed (strings T and S are equal); "IMPOSSIBLE" if none of the above works. Note that by characters "c" and "d" from the operations above, we mean any English alphabet lowercase letters. For example: • given S = "gain" and T = "again", the function should return "INSERT a"; • given S = "parks" and T = "park", the function should return "REMOVE s"; • given S="form" and T = "from", the function should return "SWAP o r"; given S = "o" and T = "odd", the function should return "IMPOSSIBLE". Assume that: • N and M are integers within the range [1..100]; • string S consists only of lowercase letters (a-z); • string T consists only of lowercase letters (a-z). In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment. Write a function: string solution (string &S, string &T); that, given two strings S and T consisting of N and M characters, respectively, determines whether string T can be obtained from string S by at most one simple operation from the set specified below. The function should return a string: • "INSERT c" if string T can be obtained from string S by inserting a single character "c" at the beginning of the string; • "REMOVE c" if string T can be obtained from string S by deleting a single character "c" from the end of the string; • "SWAP c d" if string T can be obtained from string S by swapping two adjacent characters "c" and "d" (these characters should be distinct and in the same order as in string S; exactly one swap is performed); "EQUAL" if no operation is needed (strings T and S are equal); "IMPOSSIBLE" if none of the above works. Note that by characters "c" and "d" from the operations above, we mean any English alphabet lowercase letters. For example: • given S = "gain" and T = "again", the function should return "INSERT a"; • given S = "parks" and T = "park", the function should return "REMOVE s"; • given S="form" and T = "from", the function should return "SWAP o r"; given S = "o" and T = "odd", the function should return "IMPOSSIBLE". Assume that: • N and M are integers within the range [1..100]; • string S consists only of lowercase letters (a-z); • string T consists only of lowercase letters (a-z). In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.
Expert Answer:
Answer rating: 100% (QA)
Solution The proposed solution to the given question is 1 You have to check that if any of the two strings S and T are equal return EQUAL in this case ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
The second virial coefficient B' can be obtained from measurements of the density p of a gas at a series of pressures. Show that the graph of p/ p against p should be a straight line with slope...
-
How many alkyl halides can be obtained from monochlorination of the following alkanes? Neglect stereoisomers. (a) CH3CH2CH2CH2CH3 (b) (c) (d) (e) (f) (g) (h) (i) CH3 H3 CH CHCH2CH2CHCH3 , CH3 CH3...
-
Citric acid, which can be obtained from lemon juice, has the molecular formula C 6 H 8 O 7 . A 0.250- g sample of citric acid dissolved in 25.0 mL of water requires 37.2 mL of 0.105 M NaOH for...
-
It is reported that 85% of Asian, 78% of white, 70% of Hispanic, and 38% of black children have two parents at home. Suppose there are 500 students in a representative school, of which 280 are white,...
-
Go to www.irs.gov/irb/(the IRS site containing Internal Revenue Bulletins). Locate and read IRS Notice 2008-14, 2008-4 IRB 310 and answer the following questions. a. What is the penalty for filing a...
-
1) Calculate the heat gained (inJ) during the heating of 20.0 g of H2O from 22 C to 77 C. The specific heat of H20 = 4.18J / (g) C 2) If a person can comfortably carry 20.0 kg of goldwhich has a...
-
Channey Corporation was organized on July 1. The company's charter authorizes 100,000 shares of \(\$ 2\) par value common stock. On August 1 , the attorney who helped organize the corporation...
-
Writing Improvement Exercise: Direct Openings Your Task. Revise the following openings so that they are more direct. Add information if necessary. a. Alliance Associates has undertaken a management...
-
On January 1, Sunland Corporation had 56,900 shares of no-par common stock issued and outstanding. The stock has a stated value of $4 per share. During the year, the following transactions occurred....
-
Consumer Research, owned by Chandler Robertson, is retained by large companies to test consumer reaction to new products. On January 31, 20X1, the firms worksheet showed the following adjustments...
-
How does firms get themselves in trouble when hedging with future contracts? What is the greatest danger when hedging with future contracts? What other other danger is there when hedging with future...
-
Title: STAR Stories and STAR statements Tell 3 stories from your experiences and create 3 accomplishment statements based on each of these experiences. These stories/experiences will be used to form...
-
Disney needs to close Magic Kingdom to remodel and update the castle. Disney's advisors presented two renovation alternatives: (1) a quick facelift or (2) a complete rebuild. The quick facelift would...
-
What are the thermodynamic and kinetic considerations in ultrasonic-assisted extraction, and how does this method enhance the efficiency and speed of extraction compared to conventional techniques ?
-
6. The following questions are based on RSA Algorithm. a) Describe the format of the public and private keys of the RSA Algorithm (2 marks) b) List the value of the Euler function (n) for n that is...
-
Assume all resistors (A-F) are lightbulbs with the same resistance. Construct models to compare the power (brightness) in each resistor Construct a Voltage vs Length model to show the voltage at all...
-
A marketing department was working on a project to eliminate unnecessary steps in their process for developing marketing collateral to support advertising. The team required the input of personnel...
-
What are the risks and liability factors in an audit? What are the implications to the auditor? What are the implications to the organization? How can the auditor mitigate these risks and liability...
-
The population density of worms in a particular field is 25 worms per cubic meter of soil. How many worms would there be in the top meter of soil in a field that has dimensions of 1.00 km by 2.0 km?
-
A sample of an alloy of aluminum contains 0.0898 mol Al and 0.0381 mol Mg. What are the mass percentages of Al and Mg in the alloy?
-
Calculate the energy released when 5.00 kg of uranium-235 undergoes the following fission process. The masses of and nuclei are 135.8401 amu and 95.8629 amu, respectively. Other masses are given in...
-
Suppose that \(\tau=\left\{x_{1}, \ldots, x_{n} ight\}\) are observations of iid continuous and strictly positive random variables, and that there are two possible models for their pdf. The first...
-
Deluca Solutions Inc. is an Ontario-based manufacturer. The company is listed on the TSX, but the family of founder David Deluca retains control through multiple-voting shares. Deluca undertook...
-
When can a disposal group be reported as discontinued operation rather than simply as an asset held-for-sale?
Study smarter with the SolutionInn App