Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TODO Tuj vasko shto ti gu prevede zadachu
- #include<iostream>
- #include "str_len.h"
- #include "str_match.h"
- char* revert_string(char* word)
- {
- int size_word = str_len(word);
- char* reverted_string = new char[size_word];
- for(int i=size_word-1,j=0;i>=0;i--,j++)
- {
- reverted_string[j] = word[i];
- }
- reverted_string[size_word] = '\0';
- return reverted_string;
- }
- //used for checking the terminating zero
- void print_string(char* str)
- {
- while(*str !='\0')
- {
- std::cout << *str;
- str++;
- }
- std::cout << std::endl;
- }
- bool isPalindrom(char* word)
- {
- const int LEN_WORD = str_len(word);
- if (LEN_WORD % 2 != 0)
- return false;
- char* reverted_word = new char[LEN_WORD];
- reverted_word = revert_string(word);
- return str_match(word, reverted_word);
- }
- int main()
- {
- char word[] = "DAAAAD";
- if (isPalindrom(word))
- {
- std::cout << "True " << std::endl;
- }
- else
- std::cout << "False " << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment