-2

For example, when String A has a total of 10 words and String B has total of 100 words, all words in String A are found in String B the result would be a 100% match. If half are found, it is a 50% match. What algorithm produces results like this?

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Aammad Ullah
  • 274
  • 4
  • 11
  • 2
    Please be specific. The programming language, what you've tried so far...... – Program-Me-Rev Dec 08 '15 at 19:30
  • I am doing a string matching project in php where i have to use such an algorithm to perform this task. – Aammad Ullah Dec 08 '15 at 19:36
  • Try starting with these two: 1 - [Test if a string contains a word in PHP](http://stackoverflow.com/questions/9119101/test-if-a-string-contains-a-word-in-php) 2 - [Check if a string contain multiple specific words](http://stackoverflow.com/questions/15862361/check-if-a-string-contain-multiple-specific-words) – Program-Me-Rev Dec 08 '15 at 19:43

1 Answers1

0

I will try to write a PHP like code

wordsA = explode(' ', A);
wordsB = explode(' ', B);
match = 0;
foreach (wordsA as word) {
    if (in_array(word, wordsB)) {
        match++;
    }
}
echo (count(wordsB)/match*100.'%');
Vojtech Kane
  • 559
  • 6
  • 21