palindrome

longest palindromic substring recursive solution

ぐ巨炮叔叔 提交于 2019-12-30 08:00:09
问题 I am aware of solutions that uses the bottom up dynamic programing approach to solve this problem in O(n^2). I am specifically looking for a top down dp approach. Is it possible to achieve longest palindromic substring using a recursive solution? Here is what I have tried but it fails for certain cases, but I feel I am almost on the right track. #include <iostream> #include <string> using namespace std; string S; int dp[55][55]; int solve(int x,int y,int val) { if(x>y)return val; int &ret =

Euler problem number #4

删除回忆录丶 提交于 2019-12-30 05:14:06
问题 Using Python, I am trying to solve problem #4 of the Project Euler problems. Can someone please tell me what I am doing incorrectly? The problem is to Find the largest palindrome made from the product of two 3-digit numbers . Here is what I have thus far. import math def main(): for z in range(100, 1000): for y in range(100, 1000): for x in range(1, 1000000): x = str(x) if x == x[::-1] and x == z*y: print x if __name__ == '__main__': main() 回答1: Some efficiency issues: start at the top (since

Recursive Function palindrome in Python [closed]

爷,独闯天下 提交于 2019-12-28 05:40:07
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done . Im using Python. 回答1: def

How to set FIFO and palindrome compare?

泪湿孤枕 提交于 2019-12-25 19:42:11
问题 I have this windows application 1.- So, first when I Add a number it added to listbox1 but not to list 2. I need to be add ed to listo 2 to 2.- I need the numbers be added separately... For example if I add number 202, it split on 2 after 0 after 2 3.- I need add button for FIFO, but I don't know how can I program it. 4.-Finally compare one by one it with listbox1 with listbox2 with polindrome method, and if its palindrome show message box, say "they are polindrome", if not, say "number it's

Finding the largest palindrome of the product of two 3-digit numbers in Python

老子叫甜甜 提交于 2019-12-25 09:25:11
问题 So the challenge I'm trying to solve is to find the largest palindrome made from the product of two 3-digit numbers. I'm new to Python and so my code is not elegant or refracted yet, but there is a logical error that I can't seem to find. def ispalindrome(n): rev_n = str(n)[::-1] if n == rev_n: return True else: return False first_num = 100 second_num = 100 mylist=[] while first_num < 1000: while second_num < 1000: item = first_num * second_num mylist.append(item) second_num += 1 second_num =

Setting a Limit on loops and calculating palindromes in C programming

时光怂恿深爱的人放手 提交于 2019-12-25 03:56:36
问题 So the goal of this code is to convert a user number into a palindrome. If the number is not a palindrome, calculate the number+reversed number until it becomes a palindrome. If still not a palindrome, take the sum of the last number and it's reverse and add that together, for a maximum of 10 tries. int main() { int n; int reverse = 0; //initial value will be 0 int temp; //temporary variable //Check if number is a palindrome=============================== printf("Enter an integer: "); scanf_s

Local variable not used

我们两清 提交于 2019-12-25 02:51:58
问题 I am trying to make a test of whether an inputted word is a palindrome or not (the same spelled forward and backward). From what I can see it should work but Eclipse says "The value of the local variable isPalindrome is not used" , but it is used. The problem is that even if the word is not a palindrome it says it is. import java.util.Scanner; public class Palindrome { public static void main(String[] args) { String phrase; char[] phraseLetters; int endChar; boolean isPalindrome; Scanner

C: Palindrome: Different strlen-values

核能气质少年 提交于 2019-12-24 14:07:33
问题 I'm making a function which reverses a string and checks if the string is a palindrome or not. When I test the function with a obvious palindrome like "abba", the function says it's not a palindrome. Also the forward string and the reversed string also differ in string length! #include <stdio.h> #include <string.h> char forward [] = "abba"; //The string to be reversed int size = (sizeof(forward)/sizeof(forward[0]) - 1); int j = 0; char reverse [10]; void reverser(char forward []) { printf("%s

Javascript Palindrome Logic

五迷三道 提交于 2019-12-24 04:42:07
问题 I have checked this thread: Palindrome check in Javascript But I'm more so looking to fix my own algorithm. I am just programming online right now so I do not have access to a good debugger. So any hints/debugging problems found would be greatly appreciated. Here's the code: function isPalindrome(str) { if(str !== null && str !== undefined && str !== NaN) { var strStripped = str.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()@]/g,""); var strSqueezed = strStripped.replace(/ /g, ""); var i, k; k = str

Printing all palindromes from text file

不问归期 提交于 2019-12-23 22:27:41
问题 I looked at this question: BASH Palindrome Checker. This is what the question answer shows from that thread: grep -E '^[a-z]{3,45}$' /usr/share/dict/words | while read -r word; do [ $word == `echo $word | rev` ] && echo $word; done; I understand that this is reading from "words" but have trouble trying to modify it to read from a text file instead of /usr/share/dict/words . I want to have it to read any text file I request, so I can put: source palindrome *filename* and this will print out