#include <iostream>
#include <string>
constexpr int ROWS = 3;
bool isPalindrome(const std::string& str, int left, int right) {
while (left < right) {
if (str[left++] != str[right--]) {
return false;
}
}
return true;
}
// Check and print whether substrings defined by ranges are palindromes
void checkRangesForPalindrome(const std::string& str, int rows, const int query[][2]) {
for (int i = 0; i < rows; i++) {
int start = query[i][0];
int end = query[i][1];
std::string substring = str.substr(start, end - start + 1);
std::cout << substring << ": "
<< (isPalindrome(str, start, end) ? "Palindrome" : "Not palindrome") << '\n';
}
}
int main() {
std::string str = "abcddcbeebc";
const int ranges[ROWS][2] = {{2, 5}, {5, 10}, {3, 7}};
checkRangesForPalindrome(str, ROWS, ranges);
}
/*
run:
cddc: Palindrome
cbeebc: Palindrome
ddcbe: Not palindrome
*/