Hello, friends. I did the fourth challenge on Project Euler and I'd like to know what I can do to improve the efficiency of my code. Right now it takes 1.562s to run and the source code is as follows: #include <iostream> #include <string.h> using namespace std; int Number = 0; int Reversed_Number = 0; int First_Number = 0; int Second_Number = 0; int Product = 0; int Biggest_Palindrome = 0; bool Is_Palindrome = false; string Text_Valued_Number = ""; string Text_Valued_Reversed_Number = ""; void Reverse_Number (int); void For_Loop (int,int); void Check_if_Number_is_a_Palindrome(int,int); void Show_Number(int); void For_Loop(int First_Number, int Second_Number) { for …

Member Avatar
Member Avatar
+0 forum 4

Hello programmers! After covering the basics of STL, I decided to complete the following assignment: `Write a function template palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward a backward.` So, for example, a vector with "1,2,3,2,1" would be a palindrome, but a vector containing "1,2,3,4" is not. I accidentially found out that you could do this [on StackOverFlow], template <typename T> bool isPalindrome(const T& theRef) { //solution found on the internet //check to see if theRef's contents is a palindrome return equal(theRef.cbegin(),theRef.cend(),theRef.crbegin()); } but …

Member Avatar
Member Avatar
+0 forum 1

I get an error when I try to compile my code. I can't figure it out. It says it's not declared but I think it is declared. // // // This menu-driven program is used to allow the user to choose // an application to be executed. // // // #include <string> #include <cstdlib> #include <iostream> // using namespace std; // // This class represents a string that can be tested to see if it is a palindrome class PString :: public string { public: // // THE FUNCTION PROTOTYPE FOR "isPalindrome" // THE FUNCTION RETURNS A BOOLEAN DATA VALUE …

Member Avatar
Member Avatar
+0 forum 8

A palindrome is a word or sentence that reads the same forward as it does backward. Write C++ code that read string consist of 6 characters only and check if the string palindrome word or NOT.

Member Avatar
Member Avatar
+0 forum 21

SO guys I am supposed to be making a program that will check for a palindrome but, I can not get my code to work. It seems to be stuck on the cmp part. I am not sure if this is even right I dont have much experience with masm. Any help would much be appreciated segment .data s DB 'malayalam' s_size DW 9 pal db "is a plaindrome",0x0a,0 segment .text global main extern printf main: lea rdi, [s] ;move string into rsi mov rsi, rdi ;set rsi to rdi add rsi, s_size ;add the 9 to rsi dec rsi …

Member Avatar
Member Avatar
+0 forum 2

http://ideone.com/H7YIwR Here's my code to find palindrome in string..But surely it's too slow..Is there any good algorithms for such problems..And for some cases it's not giving the right answer.Thanks for the help.

Member Avatar
Member Avatar
+0 forum 7

I a new c++ programmer, and i started to solve the SPOJ online challenges just practising , and because of my few experiance.. it gives me wrong answers alwayes. See [ **the Challenge** ](http://www.spoj.com/problems/PALIN/) here. My Code : #include<iostream> #include <vector> using namespace std; int reverse(int input) { int last_digit; int reversedNum = 0; while (input != 0) { last_digit = input % 10; reversedNum = reversedNum * 10 + last_digit; input = input / 10; } return reversedNum; } bool check(int input) { if (reverse(input) == input) { return false; } else { return true; } } int main() …

Member Avatar
Member Avatar
+0 forum 2

#include <stdio.h> #include <stdlib.h> int main() { char word[50]; int wordLength, i, reverseCount; reverseCount = 0; system( " color F5 " ); printf( "\n How many letters does the word have? : " ); scanf( "%i", &wordLength ); printf( " \n Enter word, letter by letter " ); for( i = 0; i <= wordLength; i++ ); { scanf( "%c", &word[i] ); } while( reverseCount != 0 ) { for( reverseCount = i - 1; reverseCount != 0; reverseCount-- && i++ ) { i = 0; if( word[i] != word[reverseCount] ) { printf( " \n Word is not a palindrome. …

Member Avatar
Member Avatar
+0 forum 2

I need to create a palindrome tester program that ignores spaces, punctuation and uppercase/lowercase to determine if the string given to the user is a palindrome (same beginning to end as end to beginning). HERE'S WHAT I HAVE SO FAR: String str, another = "y"; int left, right; Scanner scan = new Scanner(System.in); while(another.equalsIgnoreCase("y")) { System.out.println("Enter a potential palindrome: "); str = scan.nextLine(); left = 0; right = str.length() - 1; while(str.charAt(left) == str.charAt(right) && left < right) { left++; right--; } System.out.println(); if(left < right) System.out.println("That string is NOT a palindrome."); else System.out.println("That string IS a palindrome."); System.out.println( ); …

Member Avatar
Member Avatar
+0 forum 3

Here is slow brute force way to find the largest palindromic product of three digit integers. You could do loop and break out of it if you go under the smaller number (the second one) of best solution found so far to be more efficient etc.

Member Avatar
Member Avatar
+0 forum 3

this program is to find the largest palindrome of 3 digit numbers.this code is workig for two digit numbers but it is not working for 3 digit numbers. `` #include<stdio.h> #include<conio.h> #include<math.h> void main() { int i,j,con=0; long int num=0,res=0; clrscr(); for(i=999;i>900;i--) { for(j=999;j>i;j--) { num=(i*j); con=pal(num); if(con==0&&num>=res) res=num; } } printf("\npalindrome is %lu",res); getch(); } int pal(long int a) { long int b=0,c=a; while(a!=0) { b=(b*10)+(a%10); a=a/10; } if(c==b) return 0; else return 1; } ` on executing above code the output is 32723 but the out should be 906609..

Member Avatar
Member Avatar
+0 forum 5

Hey so this is my code for checking for palindromes...it compiles fine, the problem is it doesnt work. Basically I converted the four sentences into strings without spaces or other characters and added them to a new string called newstr....i used the newstr to check for a palindrome in the latter part of my check palindrome method(after the first for loop), which works perfectly fine normally(when i dont have to remove spaces & non letter characters first)? By looking at my code do you see anything wrong or why it isnt finding the first 3 sentences as palindromes...thanks! import java.io.PrintWriter; …

Member Avatar
Member Avatar
+0 forum 3

I need a little bit of help with my coding below. Whenever I try to run the second application it gives me momPalindrometrue dadPalindrometrue sisterPalindromefalse racecarPalindrometrue JavaPalindromefalse A man a plan a canal PanamaPalindromefalse Hurray for HollywoodPalindromefalse Mr Owl ate my metal wormPalindromefalse Was it a car or a cat I sawPalindromefalse Can I attain a CPalindromefalse nevermindPalindromefalse **** That's not what I want or am looking for, I am looking for **** mom is a palindrome dad is a palindrome sister is not a palindrome nevermind is not a palindrome etc. etc. Here's my code below to elaborate more …

Member Avatar
Member Avatar
+0 forum 1

I wanted to write a program to check if string entered is a palidrome. I wrote a program but i get errors while compiling. Can anyone help me identify errors in the program. [CODE] #include<iostream> #include<string> int main(){ string input;bool flag=false; cout<<"Enter String: "; cin>>input; cout<<"You Entered "<<input; int length= input.size(); for (int j=0; j<=length;j++){ if ((input.at(j))==(input.at(length))){ length--;flag=true; if (flag==false) break; } else {flag=false;break;} } if (flag==false) cout<<"Not A Palindrome"; else cout<<"Palindrome"; return 0; [/CODE]

Member Avatar
Member Avatar
+0 forum 7

Practicing C++ and here is two of the practice problems I pulled from the FAQ And practice post. Just want feedback and issues with the way I wrote these. Simple Calculator [CODE] #include <iostream> #include <string> #include <sstream> #include <stdlib.h> using namespace std; int main(void) { //cout << string(50, '\n'); cout << "Welcome to Simple Calc" << endl; cout << "Program will ask for two numbers and then a operation" << endl; string input = ""; string input2 = ""; char input3 = '+'; int sum = 0; while (true) { cout << "Numbers Only please, enter x at any …

Member Avatar
Member Avatar
+0 forum 1

I'm trying to make a Palindrome program, that basically returns whatever you enter, just backwards. For some reason, the cNewArray is not only couting the original array backwards, but also the original array. For example if I enter "Hello" it returns "Hello = olleHHello". I'm very new to referencing pointers and addressing and all that stuff, and I think that might be what's causing it. Can someone help? [CODE]#include <iostream> int Absolute ( int nOrigNum ) { int nAbsolute = 0; if ( nOrigNum < 0 ) { while ( nOrigNum < 0 ) { nOrigNum++; nAbsolute++; } return nAbsolute; …

Member Avatar
Member Avatar
+0 forum 7

I need help with a programing assignment for my CS 2 class, the task is to check rather a user inputted string is a palindrome meaning it is the same forwards as it is backwards. I have most of the program working, I input a string then copy it and reverse it and I got to the part were I need to compare the reversed string with the original and am getting an error message I don't understand. Here is my code so far: [CODE] #include<iostream> #include<cstdlib> #include<string> using namespace std; //class implimentations. //****************************************************************************** class pstring { private: string testString; …

Member Avatar
Member Avatar
+0 forum 8

I've searched all over, but Have not been able to find exactly what I need help on. I am creating a program that takes user input of a word and determines if it is a Palindrome or not....the catcher is I need to use stacks. They are confusing to me. I can write a simple Palindrome program without stacks, but not with. Any advice? This is what I have so far. [code=python] class Stack(): def __init__(self): self._items = [] def push(self,obj): self._items.append(obj) def pop(self): return self._items.pop() def peek(self): return self._items[-1] def isEmpty(self): return len(self._items)==0 def __len__(self): return len(self._items) def __str__(self): …

Member Avatar
Member Avatar
+0 forum 6

I've just started Python and need to write a program that tells if a string is a palindrome. Here is what I have so far. [CODE] def palp(word): if len(word) < 2: return True left_index = (0) right_index = len(word) - 1 while len(left_index) <> len(right_index): return False if left_index == right_index: left_index + 1 right_index - 1 return True [/CODE] I don't know but for some reason it doesn't return true for any palindrome except for ones with only one letter.

Member Avatar
Member Avatar
+0 forum 4

Here's a code to find out if the number is palindrome or not. [CODE] #include <stdio.h> int main() { int num,chknum1,chknum2=0,i,rmndr;/*here rmndr is remainder after mod,chknum is reversed num*/ printf("enter the number"); scanf("%d",&num); chknum1=num;/*saving num,since it is manipulated*/ for(i=0;i<=sizeof(chknum1);i++) { rmndr=num%10; num=num/10; chknum2=chknum2*10+rmndr; } printf("chknum1 %d,chknum2 %d",chknum1,chknum2); //if(chknum1=chknum2) //printf("Is palindrome"); //else //printf("is not palindrome."); return 0; } [/CODE] But it prints couple of extra zeros when the number is reversed,hence will fail to tell if the number is palindrome or not. Can anyone tell me what am I missing?

Member Avatar
Member Avatar
+0 forum 24

As [URL="http://www.daniweb.com/software-development/c/threads/377568/1625821#post1625821"]Goddess Narues' C code in C forum[/URL] was over my head and her critique of simplistic solution maybe overflowing the integer range was valid in C, I worked out a recursive solution more suitable to my brain in my preferable language. Maybe one day I put in C, now I am too lazy for that. Funny thing is that my simplistic solution is completely sufficient in Python as it has unlimitted precission integers. This code deals any numeric base and also explains about issue is 100 palindromic or not and how to accept or refuse it according to your …

Member Avatar
+0 forum 0

hi all.. how i can check there are palindrome in textbox. e.g : i input "daniweb a bewinad" thanks and please help.

Member Avatar
Member Avatar
+0 forum 7

Hello I have been working on this program for a few days and have gotten stuck. I allow the user to enter in a string and remove special characters and turn upper case characters to lower case. after all that is done i compare the characters in the string to see if it is a palindrome. My program keeps returning "not a palindrome" any help would be much appreciated thank you. [CODE]#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> char removing_char (char *str) { char *p1=str; char *p2=str; p1 = str; while(*p1 != 0) { if(ispunct(*p1) || isspace(*p1)) { ++p1; …

Member Avatar
Member Avatar
+0 forum 2

Hello I have been working on this program for a few days and have gotten stuck. I allow the user to enter in a string and remove special characters and turn upper case characters to lower case. after all that is done i compare the characters in the string to see if it is a palindrome. My program keeps returning "not a palindrome" any help would be much appreciated thank you. [CODE]#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> char removing_char (char *str) { char *p1=str; char *p2=str; p1 = str; while(*p1 != 0) { if(ispunct(*p1) || isspace(*p1)) { ++p1; …

Member Avatar
Member Avatar
+0 forum 3

Hi! First of all I would like to apologize; I dont usually ask for favours but I have blocked with a Sparc exercise. [CODE]"Write a program in assembly language SPARC applying multiple string from the keyboard. The end of the sequence of strings is determined by a null string. The program must concatenate all the strings entered, print the result, whether the resulting string is a palindrome (i.e. it is the same read forwards or backwards) and prints length."[/CODE] I have already started the code program and have no problems to "read" and "print" the string, but I am unable …

Member Avatar
+0 forum 0

i have a problem with my coding to fing wether given string is palindrome or not without using strcmp(); and srtrev(); it returns "the string is not a palindrome " for all string the [CODE]#include<stdio.h> #include<string.h> void main() { int n,i,j; char a[100]; scanf("%s",a); n=strlen(a); printf("the length ia%s,%d\n",a,n); while(i<=j) { i=0;j=n; if(a[i]==a[j]) { i++; j--; } else break; } if(i==j) { printf("the no is palindrome\n"); } else { printf("this is not palindrome\n"); } }[/CODE]

Member Avatar
Member Avatar
+0 forum 4

Hello! I need to write a program to find whether a word is a palindrome or not. What differentiates this from the other palindrome threads in this forum is that I can only use certain functions. They are: If statements, string functions (to upper, to lower, indoxof, length, substrings), for loop, do while loop, integers, decimals. My idea is to count from both ends of the string, comparing characters as I go. However, my code doesn't seem to be working past the first and last characters. I would love some helpful feedback or suggestions. My code so far: [CODE]Private Sub …

Member Avatar
Member Avatar
+0 forum 5

Hello everybody! I have to Questions to ask please: 1) How can I find the maximum value in a single linked-list recursively? this is what I tried to do: int findMax(int key){ Node max=head; while (max != null){ if (max < max.getKey()) return(max.getNext()); } } it ends up to an error.. :( 2) How can check palindrome in a single linked-list recursively? Thank you for All ^ ^

Member Avatar
Member Avatar
+0 forum 18

Hi....... This code is useful to check given string is palindrome or not. Actually, there are some other way also to check palindrome. So, be careful which code gives better efficiency. You can [COLOR="Red"]comment the line[/COLOR][COLOR="Green"]-bool caseignore= str.Equals(revstr, StringComparison.OrdinalIgnoreCase);[/COLOR] and in [B][COLOR="Red"]if[/COLOR][/B] condition you can use- if(string.Compare(str,revstr,true)==0)

Member Avatar
Member Avatar
+0 forum 1

The End.