From 5c3b97fb2572ce8940439abd0652d2a7f7a623bd Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 11 Jan 2026 13:43:39 +0200 Subject: feat(Week13): Add solutions to most exercises --- Week13/Exercise21.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Week13/Exercise21.cpp (limited to 'Week13/Exercise21.cpp') 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 +#include + +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; +} -- cgit v1.3.1-23-gd82d