Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <new>
- using std::cout;
- using std::cin;
- using std::endl;
- unsigned int len(const char* buff);
- char* makeString(const char* buff, const unsigned int& len);
- bool isPalindrome(const char* str, const int& checkF, const int& checkS);
- int main() {
- char buff[256];
- cin >> buff;
- unsigned int length = len(buff);
- cout << "Length: " << length << endl;
- if (length == 0) {
- cout << "Pali" << endl;
- }
- else {
- char* str = makeString(buff, length);
- if (isPalindrome(str, 0, length-1)) {
- cout << "Pali" << endl;
- }
- else {
- cout << "Not Pali" << endl;
- }
- }
- return 0;
- }
- bool isPalindrome(const char* str, const int& checkF, const int& checkS) {
- if (checkF >= checkS) {
- return true;
- }
- if (str[checkF] != str[checkS]) {
- return false;
- }
- return isPalindrome(str, checkF + 1, checkS - 1);
- }
- unsigned int len(const char* buff) {
- unsigned int len = 0;
- while(*buff++) {
- ++len;
- }
- return len;
- }
- char* makeString(const char* buff, const unsigned int& len) {
- char* str = new char[len];
- for (unsigned int i = 0; i < len; ++i) {
- str[i] = buff[i];
- }
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement