Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,当字符串 A 总共有 10 个单词而字符串 B 总共有 100 个单词时,字符串 A 中的所有单词都在字符串 B 中找到,结果将是 100% 匹配。如果找到一半,则为 50% 匹配。什么算法会产生这样的结果?
我将尝试编写类似 PHP 的代码
wordsA = explode(' ', A); wordsB = explode(' ', B); match = 0; foreach (wordsA as word) { if (in_array(word, wordsB)) { match++; } } echo (count(wordsB)/match*100.'%');