Commit c91f5d6e authored by Michael's avatar Michael

michael.davityan:exercise_07_32v5

parent a29e2c93
#include <iostream>
#include <unistd.h>
#include <string>
#include <cassert>
bool
palindromeCheck(const std::string &word, size_t lastIdx, size_t firstIdx = 0)
palindromeCheck(const std::string& word, size_t lastIdx, size_t firstIdx = 0)
{
if (firstIdx == lastIdx) {
if (firstIdx >= lastIdx) {
return true;
}
if (' ' == word[firstIdx]) {
if (' ' == word[firstIdx] || '\t' == word[firstIdx]) {
return palindromeCheck(word, lastIdx, firstIdx + 1);
}
if (' ' == word[lastIdx]) {
if (' ' == word[lastIdx] || '\t' == word[lastIdx]) {
return palindromeCheck(word, lastIdx - 1, firstIdx);
}
if (word[firstIdx] != word[lastIdx]) {
......@@ -31,9 +30,9 @@ main()
<< "Input the word: ";
}
std::string word;
std::cin >> word;
std::getline(std::cin, word);
const size_t lastIdx = word.size() - 1;
if (true == palindromeCheck(word, lastIdx)) {
if (palindromeCheck(word, lastIdx)) {
std::cout << "The string is palindrome\n";
} else {
std::cout << "The string is not palindrome" << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment