[Solved] How to understand this C++ palindrome code?

Taking a look at the string constructor: … (7) template <class InputIterator> string (InputIterator first, InputIterator last); You can see it is possible to create a string via iterators. The rbegin/rend iterators are InputIterators that points to the reverse positions that they refer: rend() –>”My string”<– rbegin() That said, when you pass the rbegin() and … Read more

[Solved] How to check in Java whether the input Sentence is of palindrome(not exactly, but like that) in nature or not?

First take the words of str in an array. Then check whether the words in the forward order and the reverse order are same. String[] words = str.split(” “); //splits at spaces boolean flag = true; int i, last = words.length – 1; for(i = 0; i <= last/2; i++){ if(!words[i].equalsIgnoreCase(words[last – i])){ flag = … Read more

[Solved] Palindrome Checker for numbers

The easiest way to check if a number is a palindrom would probably to treat it as a string, flip it, and check if the flipped string is equal to the original. From there on, it’s just a loop that counts how many of these you’ve encounteres: begin = int(input(‘Enter begin: ‘)) end = int(input(‘Enter … Read more

[Solved] calling a function with input [closed]

Use True/False instead of true/false. You can consider True and False as somehow ‘keywords’ in Python. For Python scripts, you don’t use def main():. Instead, try using if __name__ == ‘__main__’: under global scope. Look at this for more info. You have to print something out rather than just return a boolean variable, by using … Read more

[Solved] Odd Palindrome generator (0 to 25000)

I think, this is program you are searching for. public class Palindrome { public static void main(String[] args) { for(int i=0;i<=25000;i++){ int number=i; int reverse=0; int temp=0; while(number>0){ temp=number%10; number=number/10; reverse=reverse*10+temp; // System.out.println(rev); if(i==reverse){ if(reverse%2!=0){ System.out.println(reverse); } } } } } } 1 solved Odd Palindrome generator (0 to 25000)

[Solved] Finding the n-th prime number that is palindrome in base K

Solution: change palindrome to int palindrome ( int n,int base) { int isTrue = 1; int digitCount = digitCountBase(n,base); int power = intPow(base,digitCount-1); int original = n; while (n>0&& digitCount >0) { if (n%base != (original/power) % base &&digitCount!=1) { isTrue =0; return 0; } n=n/base; power = power /base; digitCount=digitCount-2; } return isTrue; } … Read more

[Solved] Write longest and shortest palindrome from text file

Similar to previous answer but with the following suggestions Initialize longest and shortest. Ignore case when comparing. Could still do this with SequenceEqual instead of comparing strings. May not be needed if you know you won’t be comparing Anna to annA. When checking if you found the shortest you need to remember that shortest.Length with … Read more

[Solved] How to make a Palindrome Calculator in Python

Thank you everyone, the code I found to be the answer was this: begin = int(input(‘Enter begin: ‘)) end = int(input(‘Enter end: ‘)) palindromes = palindromes = len([i for i in range(begin, end+1) if str(i) == str(i)[::-1]]) for i in range(begin, end+1): if str(i) == str(i)[::-1]: print(i,’is a palindrome’) print(‘There are’, palindromes, ‘palindrome(s) between’, begin, … Read more