diff options
feat(Week13): Add solutions to most exercises
1 files changed, 32 insertions, 0 deletions
| -rw-r--r-- | Week13/Exercise21.cpp | 32 |
diff --git a/Week13/Exercise21.cpp b/Week13/Exercise21.cpp new file mode 100644 index 0000000..280b9fa --- /dev/null +++ b/Week13/Exercise21.cpp @@ -0,0 +1,32 @@ +#include <iostream> +#include <cstring> + +unsigned min(unsigned a, unsigned b, unsigned c) { + if (a < b) + return a < c ? a : c; + return b < c ? b : c; +} + +unsigned lev(const char* a, const char* b) { + if (*b == '\0') + return strlen(a); + else if (*a == '\0') + return strlen(b); + else if (*a == *b) + return lev(a + 1, b + 1); + else + return 1 + min(lev(a, b + 1), lev(a + 1, b), lev(a + 1, b + 1)); +} + +int main() +{ + const unsigned MAX_LEN = 1024; + char line1[MAX_LEN], line2[MAX_LEN]; + + std::cin.getline(line1, MAX_LEN); + std::cin.getline(line2, MAX_LEN); + + std::cout << lev(line1, line2) << std::endl; + + return 0; +} |
