Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise17.cpp
diff options
context:
space:
mode:
1 files changed, 25 insertions, 0 deletions
-rw-r--r--Week13/Exercise17.cpp25
diff --git a/Week13/Exercise17.cpp b/Week13/Exercise17.cpp
new file mode 100644
index 0000000..952143f
--- /dev/null
+++ b/Week13/Exercise17.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+#include <cstring>
+
+bool isPalindrome(unsigned left, unsigned right, const char* str) {
+ if (left >= right)
+ return true;
+ else if (str[left] != str[right])
+ return false;
+ else
+ return isPalindrome(left + 1, right - 1, str);
+}
+
+int main() {
+ const unsigned LINE_LEN = 1024;
+
+ char line[LINE_LEN];
+ std::cin.getline(line, LINE_LEN);
+
+ if (isPalindrome(0, strlen(line) - 1, line))
+ std::cout << "Is a palindrome" << std::endl;
+ else
+ std::cout << "Not a palindrome" << std::endl;
+
+ return 0;
+}