Question: 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;

}

int getMatchCount(string s1, string s2) { if(s2.length() == 0 || s1.length() ==

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!