Hey I'm working on some homework, we just have to figure out if strings input from C++ are palindromes. He gave us some code to work with and I have most of it alright i believe but I don't know how I would insert the reverse into a storage space and then compare it to the original string can you guys help me out?
>>59868244
Here is my C++
-----------------------------------------------------
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
extern "C" {
int32_t isStringAPalindrome(const char *s);
}
static char *testStrings1[] = { "",
"#",
"Test String 1",
"tEST sTRING 2",
"Jenny, I've got your number: 867-5309",
"Toto, we're not in \"Kansas\" anymore!",
"A man, a plan, a canal - Panama!",
"Never odd or even",
"Nurses run!",
"Lewd did I live & evil I did dwel.",
"Norma is as selfless as I am, Ron."
};
#define NUM_TEST_CASES1 (sizeof (testStrings1) / sizeof (char *))
int main()
{
char substr[] = "abcd";
printf("PA#10 \n\n");
printf("\nProblem 1 output:\n");
for (int i = 0; i < NUM_TEST_CASES1; i++) {
printf("Input string [%s] yields: %s\n", testStrings1[i],
isStringAPalindrome(testStrings1[i]) ? "true" : "false");
}
printf("\n");
system("PAUSE");
return 0;
}
>>59868244
>>59868253
Heres a link to my asm its too many char to fit
https://drive.google.com/open?id=0B1DrBXWRGsK2T19qNlhwZ3IzQUU
Just Google it and do your own homework
>>59868531
I have been but Im still lost
>I don't know how I would insert the reverse into a storage space and then compare it to the original string
You wouldn't because that would be retarded. Compare the characters at the first and last position to see if they're the same and go from there.
You know that C is compiled to assembly right?
>>59868244
run bubble sort on the string characters
>>59868244
https://en.wikipedia.org/wiki/Multiple_integral
>>59868244
this is written for numbers (project euler problem 4), but is easily made for chars#include <stdio.h>
int a, b;
enum a {MAX = 1000};
int zahl = 0;
int isPalindrome();
int reverseNumber();
int main() {
for(a = 100; a < MAX; ++a) {
for(b = 100; b < MAX; ++b) {
long prod = a * b;
if(isPalindrome(prod) && prod > zahl)
zahl = prod;
}
}
printf("largest palindrome: %d\n", zahl);
}
int isPalindrome(int z) {
if(z == reverseNumber(z)) {
return 1;
}
return 0;
}
int reverseNumber(int n) {
int num = n;
int rev = 0;
int dig;
while(num > 0) {
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
return rev;
}
>>59868705
I do, but i didn't learn C or C++ my professor didn't give a shit and just passed us, only reason im taking asm is because its required for me to get a comp sci degree. I never ever want to program. I only wanna do simple IT.
>>59868880
thank you
>>59868244
OP u up? I'll do it but not wasting my time if u ain't up. Last time I did some anons asm HW he wasn't up and I wasted my time
fuck it here you gosection .data
string db "abcba",0
section .text
palindrome:
lea edi, [string]
xor eax, eax
repne scasb
sub edi, 1
lea esi, [string]
.l:
cmp esi, edi
jnb .yes
cmpsb
jne .no
sub edi, 2
jmp .l
.yes:
mov eax, 1
ret
.no:
xor eax, eax
ret
replace [string] with address of stringint palindrome(char *s);
Damn he ain't up. What a waste of some good legacy instructions
I'll bump it for you, spoonfed-kun
ASM for what? x86?