Hey there /prog/, you guys seem less than retarded, so I'm asking you for your help. I need to do some palindromes, just single words, but I'm retarded.
Does anyone know why my Sepples codes doesn't work? 'x' isn't set to the right value no matter the input, which throws off the palindrome checking function, which sucks cocks.
Here's the code. Note, I cannot use any str functions.
//Project 14 - Palindromes
#include <iostream>
using namespace std;
int main()
{
char str[100];
int x = 0; //Will be the string length
cout << "Enter a word to see if it's a palindrome: ";
cin >> str;
for(int i = 0; i < 100; i++) {
if (str[i] == '\0') {
x = i - 1;
}
}
cout << "X = " << x << endl;
for(int i = 0; i <= x; i++){
cout << str[i] << " " << str[x-i] << endl;
if (str[i] == str[x-i]) {
continue;
}
else {
cout << "That word is not a palindrome. " << endl;
return 0;
}
}
cout << "That word is a palindrome!" << endl;
return 0;
}
How the fuck did you survive the 13 previous assignments if you need help with this?
You're wasting your time with education.
McDonald's is always looking for new talent.
Name:
Anonymous2010-05-03 18:15
Here's the code. Note, I cannot use any str functions.
My first response would have been to write those functions.
Name:
Anonymous2010-05-03 18:21
Hope this helps:
s=raw_input("Enter a word to see if it's a palindrome: ");i=len(s)/2;print "That word is "+["not a palindrome. ","a palindrome!"][s[:i]==s[::-1][:i]]
section '.text' executable
public main
main:
xor eax, eax
lea edi, [msg]
call printf
xor eax, eax
lea edi, [_str]
call gets
xor edi, edi
lea esi, [_str]
@@: lodsb
inc edi
test al, al
jnz @b
dec edi
lea esi, [_str]
@@: lodsb
dec edi
test al, al
jz .palin
cmp al, [_str + edi]
je @b
.nonpalin:
xor eax, eax
lea edi, [nonpalin]
jmp printf
.palin:
xor eax, eax
lea edi, [palin]
jmp printf
section '.bss' writeable
_str: times 100 db ' '
section '.data'
msg: db "Enter a word to see if it's a palindrome: ", 0
palin: db "It's a palindrome!", 10, 0
nonpalin: db "It's not a palindrome ;_;", 10, 0
Name:
Anonymous2010-05-03 19:10
>>15
What assembler is this with the @@: / @b shit?
>>1
You need a break; in your string length counting loop after finding the terminator.
Also, you can use this more compact version instead.
while(str[x] != '\0' && x++ < 100);
x--;
Name:
Anonymous2010-05-03 19:33
>>19
Please use ++x and --x instead, they are faster.
Screen real estate shouldn't be an issue here, since if you have something else on the line with the incrementation, you're doing something wrong anyway.
Name:
Anonymous2010-05-04 18:49
#!/usr/bin/perl -p
$_="That line is "."not "x!/^(|(.)(?1)\2|.)$/."a palindrome.\n";
>>36
You only need to iterate halfway, and why are you allocating memory?
Name:
Anonymous2013-09-01 13:54
I was in Japan, but it didn't really seem like Japan because there were too many white people. The people I interacted with in the dream were all caucasian at least. The Asians were just the background people, like extras in a movie. Anyways I was walking through some sort of mall. The stores were interconnected so you walk through a door and you're in the next store. I seemed to have a set destination in mind, since I wasn't browsing any of the stores and was weaving through them all. I accidentally bump into a Japanese lady and mutter something and rush off, realizing I'm in Japan and don't actually know how to apologize. So, naturally I ask twitter.
Name:
Anonymous2013-09-01 15:25
Vodka makes me black out. I may even be blacked out whenever I read and write 4chan posts. Am I awake? Obviously Vlad the Impaler does not want it Putin the bum of a young boy. Hence the laws against homosexuality.