7 constexpr double precision = 1e-7;
9 int decimal_places = 0;
14 temp = d -
static_cast<long>(d);
16 }
while (temp > precision && decimal_places < std::numeric_limits<double>::digits10);
18 return decimal_places;
24 int i =
static_cast<int>(d);
35 std::size_t str1_len = str1.size();
36 std::size_t str2_len = str2.size();
37 std::vector<std::vector<int>> edit_distances(str1_len + 1, std::vector<int>(str2_len + 1, 0));
39 for (std::size_t i = 0; i < str1_len + 1; i++)
40 edit_distances[i][0] = i;
42 for (std::size_t j = 0; j < str2_len + 1; j++)
43 edit_distances[0][j] = j;
45 for (std::size_t i = 1; i < str1_len + 1; i++)
47 for (std::size_t j = 1; j < str2_len + 1; j++)
49 int indicator = str1[i - 1] == str2[j - 1] ? 0 : 1;
50 edit_distances[i][j] = std::min({
51 edit_distances[i - 1][j] + 1,
52 edit_distances[i][j - 1] + 1,
53 edit_distances[i - 1][j - 1] + indicator
58 return edit_distances[str1_len][str2_len];
Lots of utilities about string, filesystem and more.
int decPlaces(double d)
Count the number of decimals for a double.
int digPlaces(double d)
Count the number of digits for a double.
int levenshteinDistance(const std::string &str1, const std::string &str2)
Calculate the Levenshtein distance between two strings.