Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Having trouble with an asignment
New Posts  All Forums:Forum Nav:

Having trouble with an asignment - Page 2

post #11 of 14
Quote:
Originally Posted by jcpiont23 View Post
Not being terribly gifted with programming or terribly proficient in any one language it seems that the simplest method would be a single method instead of to compile some large array of palindromes to search through with a single palindrome.

That single method being one that would take the characters of a word and swap their positions(i.e. racecar {first letter to last position second to second to last, so on and so forth}). Then to compare the new combination of letters to the old user inputted word. If there is a match you obviously have a palindrome. If not you have a word that is not a palindrome ("sack" becomes "kcas" 'kcas' != 'sack').
This is on the right track, but it's a little less efficient than it could be. Just as a bit of a hint, you shouldn't need to use *any* assignment during your check, only comparison.

You don't always need to reverse the entire word to figure out that it's not a palindrome...
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
post #12 of 14
Quote:
Originally Posted by blangblang View Post
This is on the right track, but it's a little less efficient than it could be. Just as a bit of a hint, you shouldn't need to use *any* assignment during your check, only comparison.

You don't always need to reverse the entire word to figure out that it's not a palindrome...
Ahh i see, and now we've made a greatly efficient palindrome checker ;P.

Yes I suppose I didn't think the idea through, by the first letter of "sack" you'd already know it was not going to be a palindrome.
My SB Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
2500k Asus P8P67 GTX 470 4GB Gksill 1600mhz 
Hard DriveHard DriveOptical DriveCooling
Kingston SSDNow 1TB Samsung F3 Asus DVD Rom Heatkiller 3.0 CPU WaterBlock 
CoolingCoolingOSMonitor
EK GTX 470 Waterblock XSPC RX 360 Radiator Windows 7 Ultimate 64bit Acer 23" 
KeyboardPowerCaseMouse
Steelseries Shift Ultra x3 1000w HAF 932 Modded('UHAF') Razer Deathadder 
Mouse Pad
Razer ExactMat X 
  hide details  
Reply
My SB Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
2500k Asus P8P67 GTX 470 4GB Gksill 1600mhz 
Hard DriveHard DriveOptical DriveCooling
Kingston SSDNow 1TB Samsung F3 Asus DVD Rom Heatkiller 3.0 CPU WaterBlock 
CoolingCoolingOSMonitor
EK GTX 470 Waterblock XSPC RX 360 Radiator Windows 7 Ultimate 64bit Acer 23" 
KeyboardPowerCaseMouse
Steelseries Shift Ultra x3 1000w HAF 932 Modded('UHAF') Razer Deathadder 
Mouse Pad
Razer ExactMat X 
  hide details  
Reply
post #13 of 14
Thread Starter 
I got to the point where i can read if the string is a palindrome. Does anyone know how to read in text from a file?
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
post #14 of 14
easiest solution to this problem is copy your string character by character into an array of equal string length backwards. Then use a string comparison method to see if your two strings are equal (didn't catch what language you're using but strncmp in C or String1.equals(String2) in java*)

(If you're doing this in Java, you have to use the charAt function extensively to access each character in your string)
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Having trouble with an asignment