palindrome

Checking for palindrome string in c

这一生的挚爱 提交于 2019-12-22 10:58:59
问题 I am accepting a string as a command line argument. I want to check whether the inputted string is a palindrome or not and print the result. I have written the following code. But its displaying the result 'not palindrome' for all inputs. #include<stdio.h> #include<string.h> int main(int argc, char argv[20]) { int i; int l = strlen(argv); char str[20]; bzero(str, 20); for(i=0; i<l; i++) { str[i] = argv[i+2]; } int flag; int len = strlen(str); for(i=0; i< len/2; i++) { if(str[i] == str[len -

How does regular expression engine parse regex with recursive subpatterns?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 15:07:32
问题 This regular expression matches palindromes: ^((.)(?1)\2|.?)$ Can't wrap my head around how it works. When does the recursion end, and when regex breaks from the recursive subpattern and goes to "|.?" part? Thanks. edit: sorry I didn't explain \2 and (?1) (?1) - refers to first subpattern (to itself) \2 - back-reference to a match of second subpattern, which is (.) Above example written in PHP. Matches both "abba" (no mid palindrome character) and "abcba" - has a middle, non-reflected

How does regular expression engine parse regex with recursive subpatterns?

ⅰ亾dé卋堺 提交于 2019-12-21 15:01:05
问题 This regular expression matches palindromes: ^((.)(?1)\2|.?)$ Can't wrap my head around how it works. When does the recursion end, and when regex breaks from the recursive subpattern and goes to "|.?" part? Thanks. edit: sorry I didn't explain \2 and (?1) (?1) - refers to first subpattern (to itself) \2 - back-reference to a match of second subpattern, which is (.) Above example written in PHP. Matches both "abba" (no mid palindrome character) and "abcba" - has a middle, non-reflected

Palindrome program in C

一笑奈何 提交于 2019-12-20 07:56:22
问题 My program in C which is Palindrome has an error in its function. My function is not comparing the 2 characters in my string. When I type a single character it answers palindrome but if it is two or more always not palindrome. Code: int IntStrlength=strlen(StrWord); int IntCtr2=0; int IntCtr=1, IntAnswer; while(IntCtr<=(IntStrlength/2)){ printf(" %d %d\n", IntCtr2,IntStrlength); if(StrWord[IntStrlength] != StrWord[IntCtr2]){ IntAnswer=0; printf(" %d=Not Palindrome", IntAnswer); exit (0); }/

Can I make a code in python that ignores special characters such as commas, spaces, exclamation points, etc?

我们两清 提交于 2019-12-20 05:01:15
问题 I want to create a code that will return "true" (if I type in a palindrome regardless of case or if there are special characters in it), and "false" otherwise. The code I have so far works for phrases with no special characters such as commas, apostrophes, spaces, etc. def is_palindrome(my_str): my_str= my_str.casefold() rev_str= reversed(my_str) if list(my_str) == list(rev_str): print("True") else: print("False") when I do: print (is_palindrome("Rats live on no evil star")) it returns True

Check if given string is a palindrome using stack [closed]

若如初见. 提交于 2019-12-19 05:02:02
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Folks, I was recently interviewed and got a question on Palindrome. Given a string ( which might represent a date ), check if it's a palindrome or not using Stack. I tried to come up with solution, but he didn't like that. Can anyone show me the code snippet for it in Java ? Thanks PS : This is not a homework,

Check if given string is a palindrome using stack [closed]

十年热恋 提交于 2019-12-19 05:01:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Folks, I was recently interviewed and got a question on Palindrome. Given a string ( which might represent a date ), check if it's a palindrome or not using Stack. I tried to come up with solution, but he didn't like that. Can anyone show me the code snippet for it in Java ? Thanks PS : This is not a homework,

Convert string to palindrome string with minimum insertions

蓝咒 提交于 2019-12-18 13:09:51
问题 In order to find the minimal number of insertions required to convert a given string(s) to palindrome I find the longest common subsequence of the string(lcs_string) and its reverse. Therefore the number of insertions to be made is length(s) - length(lcs_string) What method should be employed to find the equivalent palindrome string on knowing the number of insertions to be made? For example : 1) azbzczdzez Number of insertions required : 5 Palindrome string : azbzcezdzeczbza Although

Python reverse() for palindromes

点点圈 提交于 2019-12-18 08:08:18
问题 I'm just getting started in python, and I'm trying to test a user-entered string as a palindrome. My code is: x=input('Please insert a word') y=reversed(x) if x==y: print('Is a palindrome') else: print('Is not a palindrome') This always returns false because y becomes something like <reversed object at 0x00E16EF0> instead of the reversed string. What am I being ignorant about? How would you go about coding this problem? 回答1: Try y = x[::-1] . This uses splicing to get the reverse of the

Palindrome from the product of two 3-digit numbers

走远了吗. 提交于 2019-12-18 07:25:32
问题 I want to find the largest palindrome that can be obtained through the multiplication of two 3-digit numbers. I started off with a and b both being 999, and to decrement a and b with every multiplication that occurred. a = 999 #Defining Variables b = 999 for i in range (1000): c= a*b #multiply a to b if int(str(c)[::-1]) == c: print c a = a-1 #decrement the value of a c=a*b #multiply a by the decremented a if int(str(c)[::-1]) == c: print c b = b-1 #decrement b so that both a and b have been