Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the following code to the expected output input.txt : 5 aaaa abababa abccba CPPisFun theQUICKbrownFOXjumpsOVERtheLAZYdog Expected Output: Output: Case 1 The substring (3,1) is

Modify the following code to the expected output 

input.txt :

5 aaaa abababa abccba CPPisFun theQUICKbrownFOXjumpsOVERtheLAZYdog

 Expected Output: Output: Case 1 The substring (3,1) is a Case 2 The substring (5,2) is ba Case 3 The substring (3,3) is cba Case 4 The substring (2,6) is PisFun Case 5 The substring (0,21) is theQUICKbrownFOXjumps /* * * Find the last occurrence of the longest substring without repeating characters. * You are asked to implement the functions printOutput() and longestSubstring() as specified below. * */ #include #include using namespace std; #define MAX_LENGTH 1000 // the max allowed input string length struct Result { // the structure used to store the function output int start; // the start position of the longest substring int length; // the length of the longest substring }; //-------------------------- functions to be implemented by you /* * Given a c-string str, find the last occurrence of the longest substring without repeating characters. * * Return a Result object having the start position and the length of the longest substring. * * Time Complexity Requirement: O(n) * */ Result longestSubstring(char *str) { int n = strlen(str); int res = 0,i; Result result; result.length=0; int arr[256]; for(i=0;i<256;i++){ arr[i]=-1; } i=0; for (int j = 0;j> testcase; for (int i = 0; i < testcase; i++) { fin >> str; printOutput(i + 1, str, longestSubstring(str)); } return 0; } 

input :

5 aaaa abababa abccba CPPisFun theQUICKbrownFOXjumpsOVERtheLAZYdog

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago