palindrome

Recursive method for palindrome checkup

烂漫一生 提交于 2020-02-24 10:15:14
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str

Number of distinct palindromic substrings

亡梦爱人 提交于 2020-01-31 18:01:52
问题 Given a string, I know how to find the number of palindromic substrings in linear time using Manacher's algorithm. But now I need to find the number of distinct/unique palindromic substrings. Now, this might lead to an O(n + n^2) algorithm - one 'n' for finding all such substrings, and n^2 for comparing each of these substrings with the ones already found, to check if it is unique. I am sure there is an algorithm with better complexity. I was thinking of maybe trying my luck with suffix trees

how to count the number of words of the same(PALINDROME) in java

拜拜、爱过 提交于 2020-01-22 02:09:08
问题 I'm a newbie Java Developer. I want to write code to count the number of palindrome words in the paragraph using Java. The assumptions are : User can enter a paragraph containing as many sentences as possible. Each word is separated by a whitespace, and each sentence is separated by a period and The punctuation right before or after the word will be ignored, while the punctuation inside the word will be counted. Sample Input : Otto goes to school. Otto sees a lot of animals at the pets store.

Difference between char array[100] and char *array when calling functions?

大城市里の小女人 提交于 2020-01-17 13:53:03
问题 i'd like to know why this code works fine with char tab[100] but doesn't work if I use char *tab ? fgets function takes a char* array as a parameter right ? #include <stdio.h> #include <stdlib.h> #include <string.h> Int Palindrome(char* str, int i, int j); int main() { char tab[100]; printf("Enter your string : \n"); fgets(tab, 100, stdin); int j = strlen(tab); printf("%d\n", Palindrome(tab, 0, j - 2)); return 0; } int Palindrome(char* str, int i, int j) { if (i >= j) { printf("My word is a

Difference between char array[100] and char *array when calling functions?

这一生的挚爱 提交于 2020-01-17 13:52:05
问题 i'd like to know why this code works fine with char tab[100] but doesn't work if I use char *tab ? fgets function takes a char* array as a parameter right ? #include <stdio.h> #include <stdlib.h> #include <string.h> Int Palindrome(char* str, int i, int j); int main() { char tab[100]; printf("Enter your string : \n"); fgets(tab, 100, stdin); int j = strlen(tab); printf("%d\n", Palindrome(tab, 0, j - 2)); return 0; } int Palindrome(char* str, int i, int j) { if (i >= j) { printf("My word is a

need to derive a function for palindrome

醉酒当歌 提交于 2020-01-16 13:58:42
问题 I need to derive a function which takes a string and returns whether or not that string is a palindrome and my function should return True on strings which are palindromes if spaces aren’t considered (so it should say that ’a man a plan a canal panama’ or ’was it eliots toilet i saw’ are palindromes), but it need not consider variations in capitalization or punctuation (so it may return False on ’A man, a plan, a canal - Panama!’ and ’Was it Eliot’s toilet I saw?’). I have tried def

need to derive a function for palindrome

荒凉一梦 提交于 2020-01-16 13:57:51
问题 I need to derive a function which takes a string and returns whether or not that string is a palindrome and my function should return True on strings which are palindromes if spaces aren’t considered (so it should say that ’a man a plan a canal panama’ or ’was it eliots toilet i saw’ are palindromes), but it need not consider variations in capitalization or punctuation (so it may return False on ’A man, a plan, a canal - Panama!’ and ’Was it Eliot’s toilet I saw?’). I have tried def

How do you print out a palindrome with certain characters removed using arrays?

旧巷老猫 提交于 2020-01-13 20:38:04
问题 My program is supposed to test for a palindrome and then print it out in reverse but without characters like '!', ', or '?'. So the entered input "madam I'm adam" would output "madamimadam" with no capitalization, blanks, or punctuation. I was able to write the program but how do you do that other part to take away those characters/capitalization? Also for my array, when the program runs it outputs a bunch of odd characters in between the palindrome and the palindrome in reverse when it

Python 3.2 palindrome

拈花ヽ惹草 提交于 2020-01-13 07:09:28
问题 I'm doing some python online tutorials, and I got stuck at an exercise:A palindrome is a word which is spelled the same forwards as backwards. For example, the word racecar is a palindrome: the first and last letters are the same (r), the second and second-last letters are the same (a), etc. Write a function isPalindrome(S) which takes a string S as input, and returns True if the string is a palindrome, and False otherwise. These is the code I wrote : def isPalindrome(S): if S[0] == S[-1]

Find the largest palindrome made from the product of two 3-digit numbers

折月煮酒 提交于 2020-01-11 18:01:21
问题 package testing.project; public class PalindromeThreeDigits { public static void main(String[] args) { int value = 0; for(int i = 100;i <=999;i++) { for(int j = i;j <=999;j++) { int value1 = i * j; StringBuilder sb1 = new StringBuilder(""+value1); String sb2 = ""+value1; sb1.reverse(); if(sb2.equals(sb1.toString()) && value<value1) { value = value1; } } } System.out.println(value); } } This is the code that I wrote in Java... Is there any efficient way other than this.. And can we optimize