#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0

    Help String match patten and text Algorithms in c


    Looking for an instance of one string (pattern) in another (string matching) pattern matching
    (Text). Pattern matching "weak" looking for the show, a number of errors (discrepancies)
    Lowest. Ie snippet where the number of characters other than those in the template, the lowest
    Most.


    for Example:

    if my pattern is VIVA and the text is VVIAAA.

    the match viva and vvia show 2 Discrepancy
    the match viva and viaa show 1 discrepancy
    the match viva and iaaa show 3 discrepancy

    the Function need to return the low discrepancy at that case no 1 (viva ,viaa).

    I don't find a way to solve this problem ,I wrote this code but is not help me on this problem

    pastebin.com/Z41EeUtN

    can some one help my I don't find a way


    best regards
    tamir
    Last edited by tamir yosef; September 9th, 2013 at 10:18 AM. Reason: add the problom at C programing
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480

    Disbelief


    The program you showed passes the "viva" test cases. Now, you claim that you wrote this program but don't know how to find the extrema of a few values?
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    hello to you

    i wrote this code !!

    this code dont return the low discrepancy

    if i send this VIVA and VIVVVA the Function will return 4

    but i need the low that is 1 (viva = vivv)

    i know that i need to Match the Length Of the pattern

    for Example viva length is 4 so i need to chack the 4 Cells in the text .

    and for the Second chack i need to start form the Last cell and match the 3 call .
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    can some one help me

    i cant get the to work :chomp:
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    40
    Rep Power
    19
    Your code is super excellence.

    But your understand needs to improve.

    :D

    Originally Posted by tamir yosef
    hello to you

    i wrote this code !!

    this code dont return the low discrepancy

    if i send this VIVA and VIVVVA the Function will return 4

    but i need the low that is 1 (viva = vivv)

    i know that i need to Match the Length Of the pattern

    for Example viva length is 4 so i need to chack the 4 Cells in the text .

    and for the Second chack i need to start form the Last cell and match the 3 call .
    No!!!


    VIVVVA
    VIVA

    These 2 strings are matching only 2 char at the end.
    The Levenshtein distance is 2 (red highlight).
    Last edited by Homi@th; September 11th, 2013 at 08:11 PM.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    can you help me what i need to fix the code that will do what i need

    best regards
    tamir
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    String pattern matching


    Hi tamir
    I tried to solve your problem in very simple way. Have a look. .

    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    void main()
    {
    char s1[20],s2[20];
    int i=0,count=0;
    printf("Enter string 1");
    scanf("%s",s1);
    printf("Enter string 2");
    scanf("%s",s2);
    for(i=0;i<strlen(s1)-1;i++)
    {
    if(s1[i]!=s2[i])
    count++;
    }
    printf("the match %s and %s show %d Discrepancy",s1,s2,count);
    getch();
    }

    if still u r not satisfied please let me know. . .
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    Hello thanks for your reply

    This not do what i need see that....


    for Example:
    if my pattern is VIVA and the text is VVIAAA.
    the match viva and vvia show 2 Discrepancy
    The match viva and viaa show 1 discrepancy
    The match viva and iaaa show 3 discrepancy
    evrey time the mod need to check all

    the mod need to return 1 this is the low
    see need to check all the matching .

    What you write only counter the miss match.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    I thought u ll understand the matching pattern using this.
    Anyway if the index as well as the value of the both string array is same then both string are same and function will return 1.

    Now am i able to answer your question?
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    What i need that

    i send pattern "viva" and i send text vviaaa

    the first loop chack match viva and vvia like you see v and i not match so it will save it on temp vreb.

    The second loop chack match viva and viaa like you see only a not match so it update temp verb that hold 2 to currnt 1.

    the final loop chack viva and iaaa you can see i and a and a not match so it will be 3
    So it not update the temp becuse 1 is the low value


    hope it now clear

    best regards tamir
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    Some one pls can help me?
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    some one can help me how I do it
  24. #13
  25. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    I would start with something like this.
    Code:
    #include<stdio.h>
    #include<string.h>
    
    int test ( const char *word, const char *sub ) {
      printf("Compare %s with %s\n", word, sub);
    }
    
    int evaluate ( const char *word, const char *match ) {
      size_t  wordLen = strlen(word);
      size_t  matchLen= strlen(match);
      char    temp[wordLen+1]; temp[wordLen] = 0;
      int     answer = 0, result;
      for ( size_t i = 0 ; i <= matchLen-wordLen; i++ ) {
        strncpy(temp,&match[i],wordLen);
        result = test(word,temp);
      }
      return answer;
    }
    
    int main() {
      char word[] = "VIVA";
      char match[] = "VIVVVA";
      printf("Result=%d\n", evaluate(word,match));
      return 0;
    }
    
    
    $ gcc -std=c99 foo.c
    $ ./a.out 
    Compare VIVA with VIVV
    Compare VIVA with IVVV
    Compare VIVA with VVVA
    Result=0
    Can you describe the action of test() in more detail?
    Can you write the action of test()?

    Then you need to modify evaluate() to track the minimum score so far, so it can deliver an answer to main.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by salem
    I would start with something like this.
    Code:
    #include<stdio.h>
    #include<string.h>
    
    int test ( const char *word, const char *sub ) {
      printf("Compare %s with %s\n", word, sub);
    }
    
    int evaluate ( const char *word, const char *match ) {
      size_t  wordLen = strlen(word);
      size_t  matchLen= strlen(match);
      char    temp[wordLen+1]; temp[wordLen] = 0;
      int     answer = 0, result;
      for ( size_t i = 0 ; i <= matchLen-wordLen; i++ ) {
        strncpy(temp,&match[i],wordLen);
        result = test(word,temp);
      }
      return answer;
    }
    
    int main() {
      char word[] = "VIVA";
      char match[] = "VIVVVA";
      printf("Result=%d\n", evaluate(word,match));
      return 0;
    }
    
    
    $ gcc -std=c99 foo.c
    $ ./a.out 
    Compare VIVA with VIVV
    Compare VIVA with IVVV
    Compare VIVA with VVVA
    Result=0
    Can you describe the action of test() in more detail?
    Can you write the action of test()?

    Then you need to modify evaluate() to track the minimum score so far, so it can deliver an answer to main.

    hi thanks for you post

    like I say the mod need to check the pattern "viva" to the text that I send "vviaaa"

    the mod need to do this:

    compare the pattern at to the VVIA and find the miss letter,at this case VIVA and VVIA is 2.
    than move to the next letter on the TEXT (is move form V to the second V) and compare the next 4 letter to the pattern,this case VIVA to VIAA and find the miss letter ,at this case is 1 (only V is miss).
    now need to move a letter and this case the next letter is I
    and the 4 letter after.(IAAA)
    so now the mod check VIVA and IAAA and like you see the are 3 miss (only A is on spot).

    the mod need to check and return only the lower miss on this case is 1.


    the mod need to check all and return the result (I don't send spread text ,I send all the text and the mod need to cut it and match along and return the lower number)

IMN logo majestic logo threadwatch logo seochat tools logo