Peter has two strings of the same length. The first string is fixed and the second...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Peter has two strings of the same length. The first string is fixed and the second string is rotatable. In the left rotation, the the first character is removed and added to the end of the string. In the right rotation, the last character is removed and added to the start of the string. Peter is interested in knowing the longest common prefix of both the strings. F Write an algorithm to help Peter find the minimum number of rotations required to find the longest common prefix. If no prefix is common then output -1. Input The first line of the input consists of a string firstString, representing the first string. The second line consists of a string secondString, representing the second string. Output Print an integer representing the minimum number of rotations APR 30 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 23 */ public class { 1 public st { } int // Wr retur public sta { Scanne // inp String // inpu String int res System. Question Output Print an integer representing the minimum number of rotations required to find the longest common prefix. If no prefix is common then print -1. Constraint 0 < len; where len is the length of both the strings Note The input strings are alphanumeric. The input strings consists of lowercase and uppercase alphabets (i.e. a-z and A-Z) and digits (i.e. 0-9). The string comparisons are case sensitive i.e abcd and ABCD are not considered same. Example Input: a2abccc bddda2a Output: 2 Explanation: The longest common prefix is a2ab. The minimum number of rotations required to get the longest common prefix is 3 (right rotations) O APR 30 1 2 3 4 5 3 498 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import java.util import java.lang import java.io.* /* * firstString, r secondString, rep */ public class Solut { 2 public static { } int answe // Write y return answ public static vo { Scanner in = // input for String first // input for String second int result = r System.out.pri E Question minimum number of rotations required to find the longest common prefix. If no prefix is common then print -1. Constraint 0 < len; where len is the length of both the strings Note The input strings are alphanumeric. The input strings consists of lowercase and uppercase alphabets (i.e. a-z and A-Z) and digits (i.e. 0-9). The string comparisons are case sensitive i.e abcd and ABCD are not considered same. Example Input: a2abccc bddda2a Output: 2 Explanation: The longest common prefix is a2ab. The minimum number of rotations required to get the longest common prefix is 3 (right rotations). APR O 30 2 1 import java.util.* import java.lang.*; import java.io.*; 3 4 5 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 /* * firstString, rep secondString, repres */ public class Solutic { public static in { } int answer = // Write your return answer public static void { Scanner in = n // input for f: String firstStr // input for se String secondSt int result = nun System.out.print Peter has two strings of the same length. The first string is fixed and the second string is rotatable. In the left rotation, the the first character is removed and added to the end of the string. In the right rotation, the last character is removed and added to the start of the string. Peter is interested in knowing the longest common prefix of both the strings. F Write an algorithm to help Peter find the minimum number of rotations required to find the longest common prefix. If no prefix is common then output -1. Input The first line of the input consists of a string firstString, representing the first string. The second line consists of a string secondString, representing the second string. Output Print an integer representing the minimum number of rotations APR 30 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 23 */ public class { 1 public st { } int // Wr retur public sta { Scanne // inp String // inpu String int res System. Peter has two strings of the same length. The first string is fixed and the second string is rotatable. In the left rotation, the the first character is removed and added to the end of the string. In the right rotation, the last character is removed and added to the start of the string. Peter is interested in knowing the longest common prefix of both the strings. F Write an algorithm to help Peter find the minimum number of rotations required to find the longest common prefix. If no prefix is common then output -1. Input The first line of the input consists of a string firstString, representing the first string. The second line consists of a string secondString, representing the second string. Output Print an integer representing the minimum number of rotations APR 30 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 23 */ public class { 1 public st { } int // Wr retur public sta { Scanne // inp String // inpu String int res System. Question Output Print an integer representing the minimum number of rotations required to find the longest common prefix. If no prefix is common then print -1. Constraint 0 < len; where len is the length of both the strings Note The input strings are alphanumeric. The input strings consists of lowercase and uppercase alphabets (i.e. a-z and A-Z) and digits (i.e. 0-9). The string comparisons are case sensitive i.e abcd and ABCD are not considered same. Example Input: a2abccc bddda2a Output: 2 Explanation: The longest common prefix is a2ab. The minimum number of rotations required to get the longest common prefix is 3 (right rotations) O APR 30 1 2 3 4 5 3 498 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import java.util import java.lang import java.io.* /* * firstString, r secondString, rep */ public class Solut { 2 public static { } int answe // Write y return answ public static vo { Scanner in = // input for String first // input for String second int result = r System.out.pri E Question Output Print an integer representing the minimum number of rotations required to find the longest common prefix. If no prefix is common then print -1. Constraint 0 < len; where len is the length of both the strings Note The input strings are alphanumeric. The input strings consists of lowercase and uppercase alphabets (i.e. a-z and A-Z) and digits (i.e. 0-9). The string comparisons are case sensitive i.e abcd and ABCD are not considered same. Example Input: a2abccc bddda2a Output: 2 Explanation: The longest common prefix is a2ab. The minimum number of rotations required to get the longest common prefix is 3 (right rotations) O APR 30 1 2 3 4 5 3 498 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import java.util import java.lang import java.io.* /* * firstString, r secondString, rep */ public class Solut { 2 public static { } int answe // Write y return answ public static vo { Scanner in = // input for String first // input for String second int result = r System.out.pri E Question minimum number of rotations required to find the longest common prefix. If no prefix is common then print -1. Constraint 0 < len; where len is the length of both the strings Note The input strings are alphanumeric. The input strings consists of lowercase and uppercase alphabets (i.e. a-z and A-Z) and digits (i.e. 0-9). The string comparisons are case sensitive i.e abcd and ABCD are not considered same. Example Input: a2abccc bddda2a Output: 2 Explanation: The longest common prefix is a2ab. The minimum number of rotations required to get the longest common prefix is 3 (right rotations). APR O 30 2 1 import java.util.* import java.lang.*; import java.io.*; 3 4 5 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 /* * firstString, rep secondString, repres */ public class Solutic { public static in { } int answer = // Write your return answer public static void { Scanner in = n // input for f: String firstStr // input for se String secondSt int result = nun System.out.print Question minimum number of rotations required to find the longest common prefix. If no prefix is common then print -1. Constraint 0 < len; where len is the length of both the strings Note The input strings are alphanumeric. The input strings consists of lowercase and uppercase alphabets (i.e. a-z and A-Z) and digits (i.e. 0-9). The string comparisons are case sensitive i.e abcd and ABCD are not considered same. Example Input: a2abccc bddda2a Output: 2 Explanation: The longest common prefix is a2ab. The minimum number of rotations required to get the longest common prefix is 3 (right rotations). APR O 30 2 1 import java.util.* import java.lang.*; import java.io.*; 3 4 5 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 /* * firstString, rep secondString, repres */ public class Solutic { public static in { } int answer = // Write your return answer public static void { Scanner in = n // input for f: String firstStr // input for se String secondSt int result = nun System.out.print
Expert Answer:
Related Book For
Practical Management Science
ISBN: 978-1305250901
5th edition
Authors: Wayne L. Winston, Christian Albright
Posted Date:
Students also viewed these programming questions
-
(You can use other websites for this question) The Chicago Bulls realize that they've sucked since the 90s because they have relied on one start player for too long (Jordan, Rose), and that Machine...
-
If a product becomes more popular, (a) Which curve will shift? (b) Along which curve will price and quantity move? At the new equilibrium price, will (c) Price (d) Quantity be higher or lower?
-
Solve each equation. X x + 2 + 1 X +3= 2 x + 2x
-
Washington Tennis & Education Foundation, Inc. (WTEF) is a nonprofit organization operating in the District of Columbia that provides athletic and academic programs for children from low-income...
-
Marvin's Kitchen Supply delivers restaurant supplies throughout the city. The firm adds 10 percent to the cost of the supplies to cover the delivery cost. The delivery fee is meant to cover the cost...
-
What is immediate, up-to-date information? What is Real-time systems Information governance?
-
In Fig P6.109 there are 125 ft of 2-in pipe, 75 ft of 6-in pipe, and 150 ft of 3-in pipe, all cast iron. There are three 90° elbows and an open globe valve, all flanged. If the exit elevation is...
-
Which of the following boxes should replace the question mark (?) to complete the pattern? ? A OB D A B E
-
For the following setup: What will be the time (in minutes) required to fill a 1 m container using the system if the level of the tank is constant? 4 m Ac = 2.3 m SG = 1 D 155 m 1x10- Pa.s 9.2x10-6...
-
Handy Appliances Ltd. (HANDY) is a Canadian controlled private corporation which imports and sells kitchen appliances. The following is the trial balance of HANDY for the year ended December 31,...
-
True Corporations Domestic Division produces wedge cutting machines, which use a component called stuff. They are considering an offer to outsource the production of stuff to jason Company who has...
-
To what extent can social conflict theory be utilized to analyze bullying phenomena, and what are the underlying connections, if any, between the principles of social conflict theory and the dynamics...
-
VSCC HIM department has 10,000 medical record files. Each week we need to file 3,550 records. One FTE can file 100 records per Day working a 5 day workweek. How many FTEs do we need to complete this...
-
The reliability R(t) of an item is assumed to be exponentiallydecreasing function : R(t) = exp (-t/10-4 days) What is the probability that the item will still be functioning withoutfailure at t = 300...
-
Discuss whether responsible human resources management should apply different standards for the home company and suppliers, for developed countries and developing countries, and for large companies...
-
Modify the warehouse location model so that there is an extra customer. This customer has 250 shipments per year. Try placing this new customer at various locations. For example, try placing the...
-
The 7th National Bank has two check-processing sites. Site 1 can process 10,000 checks per day, and site 2 can process 6000 checks per day. The bank processes three types of checks: vendor, salary,...
-
Use @RISK to analyze the sweatshirt situation in Problem 14 of the previous section. Do this for the discrete distributions given in the problem. Then do it for normal distributions. For the normal...
-
If price moves from disequilibrium to equilibrium, what happens to the combination of producer and consumer surplus in the market?
-
Why does nearly every purchase you make provide you with consumer surplus?
-
The chapter frames the issue of the effects of taxation in terms of its effects on producer and consumer surplus. a. What does that framework leave out of the analysis? b. How might one frame the...
Study smarter with the SolutionInn App