int main() { std::cout << "madam is a palindrome " << is_palindrome("madam") << std::endl; std::cout << "test is a palindrome " << is_palindrome("test") << std::endl; std::cout << "racecar is a palindrome " << is_palindrome("racecar") << std::endl; return 0; }
int main(int argc, char* argv[]) { int sum = 0; for(int i = 1; i < 1000000; i++) { char buffer[33]; int dec_len = sprintf(buffer, "%i", i); //printf("%s\n", buffer); if(!is_palindrome(buffer, dec_len)) { continue; } memset(buffer, '\0', 33); print_bits(i, buffer, 33); char* bin = start(buffer, 32); if(bin == NULL) { printf("null\n"); return 0; } int bin_len = strlen(bin); //printf("%s\n", bin); if(!is_palindrome(bin, bin_len)) { continue; } sum += i; } printf("%i", sum); return 0; }
bool is_palboth(char *in) { char num[32]; strcpy(num,in); if (!is_palindrome(num)) return false; to_oct(num); return (is_palindrome(num)); }
void test_length_four(void) { is_palindrome("aaaa"); is_palindrome("baab"); not_palindrome("abcd"); not_palindrome("aabb"); not_palindrome("abbc"); not_palindrome("abca"); }
int main() { const char* s1 = "palindrome"; const char* s2 = "palindromemordnilap"; if(is_palindrome(s1)) printf("uhoh"); if(is_palindrome(s2)) printf("yay!"); }
void test_long_strings(void) { is_palindrome("aaaaaaaaaaa"); is_palindrome("aaaaaaaaaaaa"); is_palindrome("abcdefgfedcba"); is_palindrome("abcdefggfedcba"); not_palindrome("abcdefghijk"); not_palindrome("aaaaaaaaaaaabaaaa"); not_palindrome("abcdxfgfedcba"); not_palindrome("abcdefggfexcba"); }
int main() { int sum = 0; int n = 1; while (n < kMax) { if (is_palindrome(n, 2) && is_palindrome(n, 10)) sum += n; n += 2; } printf("The solution is: %d\n", sum); return 0; }
int main(int argc, char* argv[]) { int sum; int i; for(sum = 0, i = 1; i < LIMIT; i += 2) { if(is_palindrome(i, 10) && is_palindrome(i, 2)) sum += i; } printf("%d\n", sum); return 0; }
int main(int argc, char *argv[]) { char word[MAX]; FILE *file; // check that we provided an arguement if(argc < 2) { printf("usage: %s dictionary-file\n", argv[0]); return 1; } // open the file for reading file = fopen(argv[1], "r"); // make sure we can successfully open the file if(file == NULL) { printf("error: can't open file %s\n", argv[1]); return 2; } else { // open was successful // loop through, line by line // finally stopping on the NULL pointer while(fgets(word, MAX, file) != NULL) { // only print the word if it's a palindrome if (is_palindrome(word)) { printf("%s\n", reverse(word)); } } // close the file fclose(file); // return successfully return 0; } }
int main (int argc, char* const argv[]) { FILE *fp = fopen(argv[1], "r"); if (fp != NULL) { char line[128]; while (fgets(line, sizeof(line), fp)) { long n = atol(line); long reversed_n = 0; for (int iterations = 0; iterations < 100; ++iterations) { reversed_n = reverse(n); n += reversed_n; if (is_palindrome(n)) { printf("%d %ld\n", (iterations + 1), n); break; } } } fclose(fp); } return 0; }
int main(){ long long int t,g,sd=0,p[12345],i,d[12345],j,h,result,a; char str[12345],b[12345],o[12345],f[12345]; scanf("%lld",&t); while(t--){ scanf("%s",str); g=strlen(str); a=g/2; for(i=0;i<g;i++){ p[i]=str[i];} //strcpy(b,str); result = is_palindrome(str); if ( result == 1 ){ printf("0\n"); } else{ if((g%2)==0){ for(i=0;i<a;i++){ d[i]=p[g-(i+1)]-p[i];} j=a; while(j--){ sd=sd+d[j];} } else{ for(i=0;i<a;i++){ d[i]=p[g-i-1]-p[i];} h=a; while(h--){ sd=sd+d[h];}} printf("%lld",sd);} }return 0; }
int main(int argc, char **argv) { float ratio = 1./CLOCKS_PER_SEC; clock_t t1 = clock(); unsigned int max_palindrome = 0; unsigned int a, b, prod; unsigned long int c = 10000; while (c > 0) { a = 999; while (a > 99) { b = 999; while (b >= a) { prod = a*b; if (prod > max_palindrome && is_palindrome(prod)) { max_palindrome = prod; } b--; } a--; } c--; } clock_t t2 = clock(); printf("%d found in %f seconds for 10,000 iterations\n", max_palindrome, \ ratio*(long)t1+ratio*(long)t2); return 0; }
int main() { char buf[1024], line[1024]; while(gets(line), strcmp(line, "DONE") != 0) { char *b = buf; for(char *p = line; *p; p++) { if(isalpha(*p)) { *b = tolower(*p); b++; } } *b = 0; if(is_palindrome(buf)) puts("You won't be eaten!"); else puts("Uh oh.."); } return 0; }
int main(){ clock_t begin, end; double time_spent; begin = clock(); // Begin solution int prod; int result=0; for (int i=999;i>99;i--){ for (int j=999;j>99;j--){ prod = i*j; if(is_palindrome(prod)){ if(prod>result) result = prod; } } } printf("Result: %d\n", result); // End solution end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf("Found result in %f time\n", time_spent); return 0; }
int is_palindrome( char* the_string , int start_char , int end_char ) { if ((( the_string[start_char] ) == ( the_string[end_char] )) || (( the_string[start_char] ) == ( the_string[end_char - 1] ))) return 1; else return 0; return is_palindrome( the_string, start_char + 1, end_char - 1 ); }
bool is_palindrome(const std::string& str, bool alpha_num_only = false, bool caseSensitive = true) { if(alpha_num_only) { std::string letters; letters.reserve(str.size()); for(std::string::const_iterator i = str.begin(); i != str.end(); i++) { if(isalnum(*i)) letters.push_back(*i); } return is_palindrome(letters.begin(), letters.end(), CharComparer(caseSensitive)); } else { return is_palindrome(str.begin(), str.end(), CharComparer(caseSensitive)); } }
void test_is_palindrome() { assert(is_palindrome(88)); assert(!is_palindrome(18)); assert(is_palindrome(121)); assert(is_palindrome(212)); assert(!is_palindrome(221)); assert(is_palindrome(1221)); assert(!is_palindrome(2211)); assert(is_palindrome(36863)); }
void input_palindrome() { char number[20]; puts("Input a number:"); scanf("%s", number); int is_palin = is_palindrome(number); show_palindrome(number, is_palin); printf("\n"); }
int main1() { string s; while (cin >> s) { cout << s << " is"; if (!is_palindrome(s)) cout << " not"; cout << " a palindrome\n"; } }
int is_palindrome( char* the_string , int start_char , int end_char ) { if( the_string[start_char] == the_string[end_char] ) { if( (end_char-start_char==1)||(end_char-start_char==2) ) return 1; return is_palindrome( the_string, start_char+1, end_char-1 ); }else return 0; }
int main (void) { char msg[MSG_LENG]; printf("Enter a message: "); read_msg (msg, MSG_LENG); result (is_palindrome (msg)); return 0; }
int is_palindrome(char* string, int start, int end){ if (string[start]==string[end]){ if (start>=end) return 1; else return is_palindrome(string, start+1, end-1); } else { return 0; } }
uint64_t Euler::exercise4() { uint64_t max_palindrome = 0; for(int i=100; i<1e3; ++i) { for(int j=100; j<1e3; ++j) { uint64_t n = i*j; if(is_palindrome(n) && n > max_palindrome) max_palindrome = n; } } return max_palindrome; }
int main(int ac, char **av) { char line[MAXLENGTH+1] ; int line_number; for ( line_number = 1 ; fgets(line, MAXLENGTH, stdin) ; line_number++ ) { if ( is_palindrome(line) ) { printf( "%d: %s\n", line_number, line) ; } } return 0 ; }
main() { char* source_string = "kayak"; char reverseString[40]; printf("The length of %s is %d\n", source_string, string_length(source_string)); reverse_string(source_string, reverseString); is_palindrome(source_string, reverseString); }
int main(int argc, char** argv) { if (2 > argc) { printf("Nombre de parametres insuffisants\n"); return 1; } char *value = argv[1]; printf("%i", is_palindrome(value)); return 0; }
int is_palindrome( char* the_string, int start_char, int end_char ){ if ( the_string [start_char] == the_string [end_char] ) return 1; if ( the_string [start_char] != the_string [end_char] ) return 0; else return is_palindrome( the_string, start_char+1, end_char-1 ); }
int main() { char* str_palin[] = { "abcba", "qwertytrewq", "zxcvbvcxz" }; char* str_nonpalin[] = { "asdfghj", "poqwert" }; for(int i=0; i<(sizeof(str_palin)/sizeof(str_palin[0])); i++) { if(!is_palindrome(str_palin[i])) { LOG_FAIL(); } } for(int i=0; i<(sizeof(str_nonpalin)/sizeof(str_nonpalin[0])); i++) { if(is_palindrome(str_nonpalin[i])) { LOG_FAIL(); } } LOG_PASS(); return 0; }
/** @brief Main program. * Set the global locale to the user's native locale. Then imbue the I/O streams * with the native locale. */ int main() { std::locale::global(std::locale{""}); std::cin.imbue(std::locale{}); std::cout.imbue(std::locale{}); std::string line{}; while (std::getline(std::cin, line)) if (is_palindrome(line)) std::cout << line << '\n'; }
bool is_palindrome(int n) { std::vector<char> digits; digits.reserve(static_cast<int>(log(static_cast<double>(n)) / log(10.0)) + 1); while(n > 0) { digits.push_back(n % 10); n /= 10; } return is_palindrome(digits.begin(),digits.end(),std::equal_to<char>()); }