Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

int getMatchCount(string s1, string s2) { if(s2.length() == 0 || s1.length() == 0) return -1; else if(s2.length() > s1.length()) return -2; int i=0, j=0, k

int getMatchCount(string s1, string s2)

{

if(s2.length() == 0 || s1.length() == 0)

return -1;

else if(s2.length() > s1.length())

return -2;

int i=0, j=0, k = 0;

int len1, len2;

len1 = s1.length();

len2 = s2.length();

for(i=0;i

{

j=0;

for(j=0;j

if(s1[i+j]!=s2[j])

break;

if(j == len2)

{

k++;

j = 0;

}

}

return k;

}

image text in transcribed

could someone fix this error and rewrite the code for me?

C++

Test Expected Got Successful For substring: he and full string hellohe110- string sub- "he"; string full-"hellohello"; int count = getMatchCount (sub, full); checkResult(sub, full, count); Expected Answer: 2 Got Answer: -2 string sub""; string full -"hellohello"; int countgetMatchCount (sub, full); checkResult(sub, full, count); Successful Successful Successful For substring: abc def and full string abe string sub "abcdef"; string full "ab"; int count getMatchCount (sub, full); checkResult(sub, full, count); Expected Answer: -2 Got Answer: 1 string sub "Satur"; string full -"SaturdaySat"; int countgetMatchCount (sub, full); checkResult(sub, full, count); Successful For substring: Satur and full string Saturdaysate Expected Answer: 1 Got Answer: -2 string sub -"he Successful Successful string full ""; int count = getMatchCount (sub, full); checkResult(sub, full, count); Your code must pass all tests to earn any marks. Try again. Hide differences

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_2

Step: 3

blur-text-image_3

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

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions