No Pairs Allowed You have a boutique that specializes in words that don't have adjacent matching...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
✩ No Pairs Allowed You have a boutique that specializes in words that don't have adjacent matching characters. Bobby, a competitor, has decided to get out of the word business altogether and you have bought his inventory. Your idea is to modify his inventory of words so they are suitable for sale in your store. To do this, you find all adjacent pairs of matching characters and replace one of the characters with a different one. Determine the minimum number of characters that must be replaced to make a saleable word. For example, you purchased words = [add, boook, break]. You will create an array with your results from the tests. Change d in add, change o in boook and no change is necessary in break. The return array result = [1,1,0]. Function Description Complete the function minimalOperations in the editor below. The function must return an array of integers, each result[i] being the minimum operations needed to fix word[i]. Constraints • 1 ≤ns 100 • 2 ≤ words[i] = 105 Each character of words[i] e 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 an integer n, the size of the array words. Each of the next n lines contains a string words[i]. ▾ Sample Case 0 Sample Input 0 5 ab aab abb abab abaaaba Sample Output 0 0 1 1 0 1 Explanation 0 • word = "ab" is already salable so result[0] = 0. • word - "aab" is not salable. We can replace word[0] = 'a' with 'g' to get the string "gab", so result[1] - 1. • word = "abb" is not salable. We can replace word[2] = 'b' with 'c' to get the string "abc", so result[2] = 1. • word = "abab" is already salable so result[3] = 0. • word = "abaaaba" is not salable. We can replace word[3] = 'a' with 'b' to get the string "abababa" and result[4] = 1. We then return result = [0, 1, 1, 0, 1). YOUR ANSWER For help on how to read input and write output in Python 3, click here. Click here to know more about handling STDIN and STDOUT in other languages. Sample Problem: Write a program that adds two numbers prints the sum to STDOUT. Read the input from STDIN. The first line of your input will contain an integer (N) that tells you how many more lines there are in the input. Each of the subsequent N lines contain 2 integers). You need to print the sum of each pair on a separate line of STDOUT. Sample Input: 3 15 3 10 999 -34343 Sample Output: 6 13 -33344 SOLUTION CODE nint (input()) for X in range(n): a, b = map(int, input().strip().split()) print (a + b) Draft saved 02:04 pm 1#!/bin/python3. 10 11 # 12 # Complete the 'minimal operations' function below. 13 # 14 14 #The function is expected to return an INTEGER_ARRAY. #The function accepts STRING_ARRAY words as parameter. 15 15 16 16 17 18 19 20 21 if # # def minimalOperations (words): # Write your code here name ===_____main_ Original Code Python 3 @ ✩ No Pairs Allowed You have a boutique that specializes in words that don't have adjacent matching characters. Bobby, a competitor, has decided to get out of the word business altogether and you have bought his inventory. Your idea is to modify his inventory of words so they are suitable for sale in your store. To do this, you find all adjacent pairs of matching characters and replace one of the characters with a different one. Determine the minimum number of characters that must be replaced to make a saleable word. For example, you purchased words = [add, boook, break]. You will create an array with your results from the tests. Change d in add, change o in boook and no change is necessary in break. The return array result = [1,1,0]. Function Description Complete the function minimalOperations in the editor below. The function must return an array of integers, each result[i] being the minimum operations needed to fix word[i]. Constraints • 1 ≤ns 100 • 2 ≤ words[i] = 105 Each character of words[i] e 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 an integer n, the size of the array words. Each of the next n lines contains a string words[i]. ▾ Sample Case 0 Sample Input 0 5 ab aab abb abab abaaaba Sample Output 0 0 1 1 0 1 Explanation 0 • word = "ab" is already salable so result[0] = 0. • word - "aab" is not salable. We can replace word[0] = 'a' with 'g' to get the string "gab", so result[1] - 1. • word = "abb" is not salable. We can replace word[2] = 'b' with 'c' to get the string "abc", so result[2] = 1. • word = "abab" is already salable so result[3] = 0. • word = "abaaaba" is not salable. We can replace word[3] = 'a' with 'b' to get the string "abababa" and result[4] = 1. We then return result = [0, 1, 1, 0, 1). YOUR ANSWER For help on how to read input and write output in Python 3, click here. Click here to know more about handling STDIN and STDOUT in other languages. Sample Problem: Write a program that adds two numbers prints the sum to STDOUT. Read the input from STDIN. The first line of your input will contain an integer (N) that tells you how many more lines there are in the input. Each of the subsequent N lines contain 2 integers). You need to print the sum of each pair on a separate line of STDOUT. Sample Input: 3 15 3 10 999 -34343 Sample Output: 6 13 -33344 SOLUTION CODE nint (input()) for X in range(n): a, b = map(int, input().strip().split()) print (a + b) Draft saved 02:04 pm 1#!/bin/python3. 10 11 # 12 # Complete the 'minimal operations' function below. 13 # 14 14 #The function is expected to return an INTEGER_ARRAY. #The function accepts STRING_ARRAY words as parameter. 15 15 16 16 17 18 19 20 21 if # # def minimalOperations (words): # Write your code here name ===_____main_ Original Code Python 3 @
Expert Answer:
Related Book For
Introduction to Managerial Accounting
ISBN: 978-0078025792
7th edition
Authors: Peter Brewer, Ray Garrison, Eric Noreen
Posted Date:
Students also viewed these programming questions
-
Have you ever tried to get out of jury duty? About 25% of those called will find an excuse (work, poor health, travel out of town, etc.) to avoid jury duty. If 12 people are called for jury duty: (a)...
-
Is it possible for a matrix to get out of control because of too many small projects, each competing for the same shared resources? If so, how many projects are too many? How can management control...
-
Have you ever tried to get out of jury duty? About 25% of those called will find an excuse (work, poor health, travel out of town, etc.) to avoid jury duty. (a) If 12 people are called for jury duty,...
-
Alton division (A) and Birmingham division (B) are two manufacturing divisions of Conglom plc. Both of these divisions make a single standardized product; A makes product I and B makes product J....
-
The following transactions relate to Hawkins, Inc., an office store wholesaler, during June of this year. Terms of sale are 2/10, n/30. The company is located in Los Angeles, California. June 1 Sold...
-
Connor Chemical Company's plant processes batches of organic chemical products through three stages after starting with raw materials: (1) Mixing and blending, (2) Reaction chamber, and (3)...
-
Redesign the VOCs adsorber of Example 9.15 for a breakthrough time of \(4.0 \mathrm{~h}\). The pressure drop through the bed [calculated using the Ergun equation (2-95)] should not exceed \(1.0...
-
On July 1, 2012, Bliss Industries, Inc. issued $24,000,000 of 20-year, 11% bonds at a market (effective) interest rate of 14%, receiving cash of $19,200,577. Interest on the bonds is payable...
-
Your company has decided to adopt a NoSQL database management system for storage and processing of big data. You have been asked to investigate alternative NoSQL technologies. (a) Explain the...
-
1. If Amanda and David wanted to transfer the ownership of all 5 policies to Paws and Claws today through an absolute assignment, calculate the total amount of their donation receipt they would be...
-
Suppose that you have just purchased a share of stock for $25. the most recent dividend was $1.6 and dividends are expected to grow at a rate of 5% indefinitely. what must your required return be on...
-
Assume that you have purchased a new car and after your down payment, youborrowed $20,000 from a bank to pay for the car. Also assume that you have agreed to pay off this loanby making equal monthly...
-
The strategic management process includes activities that managers take to help put their firms in the best position to be successful in the market. Which of the following is not a part of the...
-
What kind of strategy should a company in Canada selling Men's shoes use when trying to enter a market in China? Global, multi domestic or transnational strategy? Be detailed with your answer.
-
1. In what ways do you find writing conventions differ across the disciplines? What are some examples? 2. What are some of the common genres and writing purposes? 3. What is the role of feedback in...
-
Based on the document, PayTran implemented a series of fraud detection process changes for one of their clients, IWantIt, to help reduce the level of fraudulent transactions. After these changes,...
-
Beacon, Incorporated reported the following amounts at the end of the first year of operations: Common stock $ 332,000 Sales revenue $ 1,328,000 Total assets $ 996,000 Dividends declared and paid $...
-
Sue Deliveau opened a software consulting firm that immediately paid $2,000 for a computer. Was this event a transaction for the business?
-
The financial statements for Castile Products, Inc., are given below: Account balances at the beginning of the year were accounts receivable, $25,000; and inventory, $60,000. All sales were on...
-
Cardinal Company is considering a project that would require a $2,975,000 investment in equipment with a useful life of five years. At the end of five years, the project would terminate and the...
-
The following data relating to units shipped and total shipping expense have been assembled by Archer Company, a wholesaler of large, custom-built air-conditioning units for commercial buildings:...
-
An old-fashioned tire swing exerts a force on the branch and a torque about the point where the branch meets the trunk. If you hang the swing closer to the trunk, this will --the force and-- the...
-
Which of these objects is in static equilibrium? A. B. C. D.
-
A beam with a pivot on its le ft end is suspended from a rope. Tn which direction is the force of the pivot on the beam? A. B. C. D. E.
Study smarter with the SolutionInn App