Error in the algorithm ofBoyer-Moore

Asked

Viewed 30 times

0

I’m studying how to count how many times one string appears on the other, and I found this site Website link, in it has the algorithm deBoyer-Moore, which finds number of occurrences of a in b, but only that when I pass the values the function returns 1, when it should return 6, I am making some error in the function call

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int trivial ( char a[], int m,  char b[], int n)
{
   int i, j, k, ocorre = 0;
    for (k = m; k <= n; ++k)
    {
        for (i = m, j = k; i >= 1; --i, --j)
         if (a[i] != b[j]) break;
       if (i < 1) ++ocorre;
   }
  return ocorre;
}

int main(int argc, char** argv)
{

    char a[] = "78954";
    char b[] = "7895478954789547895447895478954";
    int tamA = strlen(a);
    int tamB = strlen(b);
    int resultado = trivial(a, tamA, b, tamB);
    printf("%d\n", resultado);
    return 0;
 }
  • Your code doesn’t even compile.

  • Hello cool look here link https://ideone.com/T0ZiLy he compiled of good

  • Yeah, he ate something here at the time of the necklace. but there is still nothing in your question that indicates about the problem, what you want, gives information, play the code and tell us to turn around to solve the problem is not cool. Alias I’ll tell you that you keep making the same mistakes and still can not solve the problems, this means that you are not learning and need to change the methodology that learning.

  • Okay, I know you don’t like to talk about methodology, but could you give me a learning methodology tip

  • Take a course, look for books, structure learning, do it continuously, only move on to something more complex when mastering what is most basic. I’m sure you can’t explain what this code is doing. It’s too complex for your current knowledge. It is burning stages and is not learning because knowledge builds one step at a time, skips one and everything becomes more difficult. Me and other people give answers that show better ways to do it, you keep doing it the disorganized way and ignore what’s been past. There’s no methodology that works.

  • All right, thank you

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.