int MaxProduct() { int min = pow1(10,DIGITS-1); int max = 0; int i = 0; int num1 = 0, num2 = 0; int maxProduct = 0; for(i=0; i<DIGITS; i++) { max = max*10 + 9; } for(num1=max; num1 >= min; num1--) { for(num2=num1-1; num2 >= min; num2--) { if(IsPalindrome(num1*num2)) { maxProduct = maxProduct < num1*num2 ? num1*num2 : maxProduct; } } } return maxProduct; }
int main() { std::ios_base::sync_with_stdio(false); std::string line = ""; while (std::getline(std::cin, line)) { if (IsPalindrome(line)) { std::cout << line << std::endl; } } return 0; }
static bool IsPalindrome(string str) { int len; len = StringLength(str); if (len <= 1) { return (TRUE); } else { return (IthChar(str, 0) == IthChar(str, len - 1) && IsPalindrome(SubString(str, 1, len - 2))); } }
int main(void) { char fck[100]; while(1) { printf("please input any str:\n"); scanf("%s", fck); printf("IsPalindrome ret = %d\n", IsPalindrome(fck)); printf("CheckPalindrome2 ret = %d\n", CheckPalindrome2(fck, strlen(fck))); } return 0; }
int main(void) { std::cout << "IsPalindrome( 0 ) = " << ( IsPalindrome(0) ? "TRUE" : "FALSE" ) << std::endl; std::cout << "IsPalindrome( 11 ) = " << ( IsPalindrome(11) ? "TRUE" : "FALSE" ) << std::endl; std::cout << "IsPalindrome( 123321 ) = " << ( IsPalindrome(123321) ? "TRUE" : "FALSE" ) << std::endl; std::cout << "IsPalindrome( 123456 ) = " << ( IsPalindrome(123456) ? "TRUE" : "FALSE" ) << std::endl; int maxPalindrome = 0; for( int i=999; i>=100; i-- ) { for( int j=999; j>=100; j-- ) { int p = i*j; if( IsPalindrome(p) && p > maxPalindrome ) maxPalindrome = p; } } std::cout << "Max Palindrome = " << maxPalindrome << std::endl; return 0; }
void DFS(string& str, int startIdx, vector<string>& curSubStrs, vector<vector<string>>& result) { if (startIdx == str.size()) { result.push_back(curSubStrs); return; } for (int i = startIdx; i < str.size(); ++i) { if ( IsPalindrome(str, startIdx, i) ) { curSubStrs.push_back(str.substr(startIdx, i-startIdx+1)); DFS(str, i+1, curSubStrs, result); curSubStrs.pop_back(); } } }
main() { string str; printf("This program checks for palindromes.\n"); printf("Indicate end of input with a blank line.\n"); while (TRUE) { printf("Enter a string: "); str = GetLine(); if (StringEqual(str, "")) break; if (IsPalindrome(str)) { printf("'%s' is a palindrome.\n", str); } else { printf("'%s' is not a palindrome.\n", str); } } }
void ch16ex1(void) { std::cout << IsPalindrome("abab") << std::endl; }