It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




7年前关闭。




我不相信标准库可以提供任何东西来计算两个字符串之间的距离,而且我似乎在Boost StringAlgo中找不到任何东西。那么,还有其他我可以使用的库吗?

我对算法不太挑剔。 Jaro-Winkler很好,Levenshtein也很好,我乐于接受建议,我不想编写别人已经编码的东西。

最佳答案

您没有使用实际的距离度量来定义问题,因此我认为它只需要满足“Metric (mathematics)”中的条件:



假设我们这样定义d:

          { 0 if x = y
d(x, y) = {
          { 1 otherwise

因此,满足前三个条件:
  • d(x, y) ≥ 0
  • d(x, y) = 0 iff x = y
  • d(x, y) = d(y, x) = 0 for x = yd(x, y) = d(y, x) = 1 for x ≠ y

  • 对于最后一种情况,有两种情况:
  • d(x, z) = 0。右侧唯一可以想到的值是012,它们中的任何一个都可以满足条件。
  • d(x, z) = 1。假设右侧不大于或等于1。这意味着它必须为零。然后,右边的两个术语都必须为0,这意味着x = yy = z。第二个条件表示x = z,这又表示d(x, z) = 0。这是一个矛盾,因此右侧必须大于或等于1。

  • 然后,我们可以将指标定义为:
    int d(std::string x, std::string y) {
        if (x == y) {
            return 0;
        } else {
            return 1;
        }
    }
    

    关于c++ - 两根弦之间的距离,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15136500/

    10-10 22:41