diff --git a/lab2/edit_distance.cc b/lab2/edit_distance.cc index 905aeb4..7f635c9 100644 --- a/lab2/edit_distance.cc +++ b/lab2/edit_distance.cc @@ -1,14 +1,13 @@ -#include -#include -#include #include +#include +#include -int edit_distance(const std::string& s1, const std::string& s2) { +int edit_distance(const std::string &s1, const std::string &s2) { size_t m = s1.size(); size_t n = s2.size(); // Create a 2D DP table - std::vector> dp(m + 1, std::vector(n + 1)); + std::vector> dp(m + 1, std::vector(n + 1)); // Fill the base cases for (size_t i = 0; i <= m; ++i) @@ -23,13 +22,14 @@ int edit_distance(const std::string& s1, const std::string& s2) { if (s1[i - 1] == s2[j - 1]) { dp[i][j] = dp[i - 1][j - 1]; // No operation needed } else { - dp[i][j] = 1 + std::min({dp[i - 1][j], // Deletion - dp[i][j - 1], // Insertion - dp[i - 1][j - 1] // Substitution - }); + dp[i][j] = 1 + std::min({ + dp[i - 1][j], // Deletion + dp[i][j - 1], // Insertion + dp[i - 1][j - 1] // Substitution + }); } } } - return dp[m][n]; + return static_cast(dp[m][n]); } diff --git a/lab2/edit_distance.h b/lab2/edit_distance.h index 71765ad..6ddc48a 100644 --- a/lab2/edit_distance.h +++ b/lab2/edit_distance.h @@ -1,18 +1,17 @@ -#include -#include #include -#include /** * @brief Computes the edit distance (Levenshtein distance) between two strings. * * The edit distance is defined as the minimum number of single-character edits - * (insertions, deletions, or substitutions) required to transform one string into the other. + * (insertions, deletions, or substitutions) required to transform one string + * into the other. * - * This implementation uses dynamic programming to compute the distance efficiently. + * This implementation uses dynamic programming to compute the distance + * efficiently. * * @param s1 The first string. * @param s2 The second string. * @return The edit distance between the two strings. */ -int edit_distance(const std::string& s1, const std::string& s2); +int edit_distance(const std::string &s1, const std::string &s2);