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/Exercise04.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Week13/Exercise04.cpp (limited to 'Week13/Exercise04.cpp') diff --git a/Week13/Exercise04.cpp b/Week13/Exercise04.cpp new file mode 100644 index 0000000..0fdc462 --- /dev/null +++ b/Week13/Exercise04.cpp @@ -0,0 +1,38 @@ +#include +#include + +/* Два начина по които да имплементираме обръщането на низа */ + +void revText1(unsigned left, unsigned right, char* str) { + if (left < right) { + char tmp = str[left]; + str[left] = str[right]; + str[right] = tmp; + + revText1(left + 1, right - 1, str); + } +} + +void revText2(char* left, char* right) { + if (left < right) { + char tmp = *left; + *left = *right; + *right = tmp; + + revText2(left + 1, right - 1); + } +} + +int main() { + const unsigned MAX_LEN = 1024; + + char line[MAX_LEN]; + std::cin.getline(line, MAX_LEN); + + // revText1(0, strlen(line) - 1, line); + revText2(line, line + strlen(line) - 1); + + std::cout << line << std::endl; + + return 0; +} -- cgit v1.3.1-23-gd82d