Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include int strlength(char str[], int length, int *first, int *last) { char curr_char = str[0]; int start=0;; int finish=0; int curr_start=0; int max_length =

image text in transcribed

#include  #include  int strlength(char str[], int length, int *first, int *last) { char curr_char = str[0]; int start=0;; int finish=0; int curr_start=0; int max_length = 1; for (int i=0; i max_length) { max_length = curr_length; start = curr_start; finish = i; } } else { curr_char = str[i]; curr_start = i; } } *first = start; *last = finish; return max_length; } void main(int argc, char *argv[]) { int first, last; char str1[30]="pqrpqrpqrpqrtttrrttrrrttpqrpqr"; int n = strlength(str1, 30, &first, &last); printf("String 1 = %s ",str1); printf("String length = %d, first = %d, last = %d ", n, first, last); char str2[21]="abcbbcabbabbabcbbcbca"; n = strlength(str2, 21, &first, &last); printf("String 2 = %s ",str2); printf("String length = %d, first = %d, last = %d ", n, first, last); }
Problem 4 [1 pt]. This problem is a coding problem, unrelated to probability, but good practice for algorithm design. Attached is a program strlength.c, and it has a function int strlength(char str[ ], int length, int * first, int *last) /* 'length' is the length of string str[ ]) */ that - Returns the length of the longest substring of str[ ] of a single character - Sets "first" and "last" as the indices where the substring starts and ends For example, aaabaabbababbbba has the longest substring bbbb which has length 4, and starts at position 11 and ends at position 14. Modify the function strlength(), so that it finds the longest substring with at most two distinct characters. For example

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

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Are these written ground rules?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago