InterviewSolution
| 1. |
0 and 3 (or 3 and 0) as 3 + 7 = 10 |
|
Answer» #INCLUDE <string> #include <stdexcept> #include <iostream> using NAMESPACE std; class Palindrome { public: static bool isPalindrome(const std::string& word) { static int i,j; static int count; while(word[count]!='\0') count++; cout<<"count is"<<count<<endl; i=0; j=count-1; while(i<j) { cout<<endl<<"word[i]"<<word[i]<<endl<<"word[j]"<<word[j]<<endl; if(tolower(word[i++])!=tolower(word[j--])) { cout<<endl<<word<<" is not a Palindrome"<<endl; return 0; } } cout<<endl<<word<<" is a palindrome"<<endl; count = i = i= 0; return 1; } }; #ifndef RunTests int main() { std::cout << Palindrome::isPalindrome("Deleveled"); std::cout << Palindrome::isPalindrome("Malayalam"); std::cout << Palindrome::isPalindrome("Bab"); std::cout << Palindrome::isPalindrome("Balam"); } #ENDIF |
|