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,...
-
On September 1, 2016, Dougherty Corp. accepted a six-month, 7%, $45,000 interest bearing note from Rozelle Company in payment of an account receivable. Dougherty's year-end is December 31. Rozelle...
-
55.3 million excess electrons are inside a closed surface. What is the net electric flux through the surface?
-
1. Read the text materials on feedforward, concurrent, and feedback control. 2. Read the Control Problem Situation and be prepared to resolve those control problems in a group setting. 3. Your...
-
On September 30, 2015, Ericson Company negotiated a 2-year, 1,000,000 dudek loan from a foreign bank at an interest rate of 2 percent per year. It makes interest payments annually on September 30 and...
-
The scope of a project is expanded through the formal change control process, causing the schedule to be extended beyond the original due date. This is an example of which type of influence?
-
Assume you have an graph as following. Use Dijkstra Algortihm to calculate shortest path from vertex A to every vertex (manuel calculation). Write the Dijkstra code to generate this graph and find...
-
In 2022 the Ayayai Corp. had net credit sales of $ 900000 . On January 1, 2022, the Allowance for Doubtful Accounts had a credit balance of $ 21900 . During 2022, $ 33000 of uncollectible accounts...
-
1. Why is insurance important? Choose two types of insurance and discuss their characteristics. 2. What questions should you ask yourself before you choose a life insurance policy? 3. What factors...
-
On June 1, Waterway Company borrows $111,000 from First Bank on a 6-month, $111,000, 8% note. Prepare the entry on June 1. (Credit account titles are automatically indented when amount is entered. Do...
-
If Western Civilization was to begin recognizing and honoring the Divine Feminine, what woman (or women) would you suggest as a model for figurines, paintings, statues, and/or pictures on a coin?...
-
a CFO of a hospital need to reduce its budget and The CFO's first step for budget reduction is identifying the areas where the hospital needs budget reduction and developing a plan that outlines the...
-
A refrigerator uses 40.0 of work to exhaust 90.0 J from a heat reservoir at 0.00C. What is the coefficient of performance for the refrigerator?
-
1) Write a paragraph the potential reasons for choosing a hub versus a switch, whether it be cost, speed, security or other. 2) What might prevent wireless technology from being used extensively in...
-
In your readings, there were many examples given for nurturing close family relationships in this ever-evolving technological society we live in Based upon your readings and research describe three...
-
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...
-
What is a business strategy? Do you agree with the definition proposed? Illustrate your answer with examples.
-
Consider one of the following firms. Read the description of a business strategy in the text. Go to the firm's website and use it to gain an understanding of the business strategy. Look at elements...
-
Which quote at the front of the chapter do you find the most insightful? Why? Under what circumstances would its implications not hold?
Study smarter with the SolutionInn App