Valhalla Legends Forums Archive | C/C++ Programming | Re:Palindrome Detection

AuthorMessageTime
Mephisto
What the hell is that? Did you come up with some random code to put on here with some explanation completely off topic from your original question?

Also, just because it runs, does not mean it should be done that way...I'm surprised your compiler would even compile that (unless you're using Microsoft's which doesn't *just* support ANSI standard code; Microsoft likes to have their own standards and things on their own way. For instance, you could use void main() legally without warnings or errors in MSVC++ or specify scope of variables in your loops, etc.).
May 11, 2004, 1:47 PM
iago
[quote author=Mephisto link=board=30;threadid=6735;start=0#msg59525 date=1084283249]
What the hell is that? Did you come up with some random code to put on here with some explanation completely off topic from your original question?

Also, just because it runs, does not mean it should be done that way...I'm surprised your compiler would even compile that (unless you're using Microsoft's which doesn't *just* support ANSI standard code; Microsoft likes to have their own standards and things on their own way. For instance, you could use void main() legally without warnings or errors in MSVC++ or specify scope of variables in your loops, etc.).
[/quote]

There's nothing wrong with loop-scoped variables.

And did you just talk down at Microsoft?

Anyway, let me say it again, talk to your teacher. You can't do a lot of what you are doing in your code.
May 11, 2004, 4:16 PM
Zeller
[quote author=Mephisto link=board=30;threadid=6735;start=0#msg59525 date=1084283249]
... or specify scope of variables in your loops ...
[/quote]

Can you give an example or something about that. I dont understand what you mean.
May 11, 2004, 6:54 PM
Tuberload
[quote author=Zeller link=board=30;threadid=6759;start=0#msg59600 date=1084301644]
[quote author=Mephisto link=board=30;threadid=6735;start=0#msg59525 date=1084283249]
... or specify scope of variables in your loops ...
[/quote]

Can you give an example or something about that. I dont understand what you mean.
[/quote]
[code]
while (true)
{
int loop_scoped_variable = 1;
}
[/code]
May 11, 2004, 9:38 PM
Mephisto
No, I meant you can select that you can declare variables in loops and they will still be in scope outside of the loop. I believe you can do this in MSVC++, if not, then I'm mistaken...But I'm pretty confident you can.
May 11, 2004, 11:19 PM
Myndfyr
[quote author=Mephisto link=board=30;threadid=6759;start=0#msg59659 date=1084317594]
No, I meant you can select that you can declare loops in variables and they will still be in scope outside of the loop. I believe you can do this in MSVC++, if not, then I'm mistaken...But I'm pretty confident you can.
[/quote]

You meant that you can declare variables in loops and they will still be in scope outside of the loop. This is not proper according to C++ 99 (I believe that's the spec) -- variables inside of a loop remain in scope only for that loop.
May 12, 2004, 12:23 AM
Eibro
[quote author=Mephisto link=board=30;threadid=6759;start=0#msg59659 date=1084317594]
No, I meant you can select that you can declare loops in variables and they will still be in scope outside of the loop. I believe you can do this in MSVC++, if not, then I'm mistaken...But I'm pretty confident you can.
[/quote]Yes, only VC6 had this problem. It's fixed in VS.net 2002/2003, though there's a compiler option to toggle whether it's enforced or not.
Ex.[code]for ( int i =0; i < 10; ++i ) { /* code.. */ } i = 25[/code] is illegal.
May 12, 2004, 2:37 AM
Mephisto
Which is exactly what I was pointing out. And in Eibro's example, you could make his example legal in MSVC++. This is because Microsoft supports ANSI/ISO C++, but they have their own standards if you want to call it that, and support things that are illegal in C++ standards, such as using void main() function definitions, and variable loop scope resolution.

Thanks MyndFyre, typo. ;)
May 12, 2004, 3:32 AM
Adron
[quote author=Mephisto link=board=30;threadid=6759;start=0#msg59724 date=1084332748]
Which is exactly what I was pointing out. And in Eibro's example, you could make his example legal in MSVC++. This is because Microsoft supports ANSI/ISO C++, but they have their own standards if you want to call it that, and support things that are illegal in C++ standards, such as using void main() function definitions, and variable loop scope resolution.

Thanks MyndFyre, typo. ;)
[/quote]

You mean, they support things that are different from the latest C++ standards, i.e. they are backwards compatible. Being optionally backwards compatible is a very good thing.
May 12, 2004, 10:02 AM
Mephisto
Of course. I don't think I ever said it was a bad thing, I was just pointing out that they support other things in C/C++ that isn't compatable with ANSI/ISO C/C++ standard.

However, if people just learning start out using MSVC++ and tutorials on MSDN and such (which use void main() definitions, and other things that may be illegal in C/C++), the new one starting may develop bad coding. :p It should be important to know what the C/C++ standards are and how to properly code in them, and then take advantage of what Microsoft has to offer in their compilers that is illegal in C/C++ standards if you want to...
May 12, 2004, 12:58 PM
AC_Drkan
Look at my post in Palindrome Detection
May 13, 2004, 3:06 PM
Adron
[quote author=AC_Drkan link=board=30;threadid=6759;start=0#msg59979 date=1084460790]
Look at my post in Palindrome Detection
[/quote]

Which one? I posted multiple working answers to your problem...
May 13, 2004, 10:52 PM
St0rm.iD
Took me a couple minutes and one bug to whip this up. Was a nice little exercise! :)
[code]
(define is-palindrome-helper
(lambda (str start length)
(if (> start (quotient length 2))
#t
(and
(equal? (string-ref str start)
(string-ref str (- (- length start) 1)))
(is-palindrome-helper str (+ start 1) length)
)
)
)
)

(define is-palindrome
(lambda (str)
(is-palindrome-helper
str
0
(string-length str))))

(is-palindrome "racecar")
[/code]
May 14, 2004, 8:59 PM
kamakazie
[quote author=St0rm.iD link=board=30;threadid=6759;start=0#msg60130 date=1084568356]
Took me a couple minutes and one bug to whip this up. Was a nice little exercise! :)
[code]
(define is-palindrome-helper
(lambda (str start length)
(if (> start (quotient length 2))
#t
(and
(equal? (string-ref str start)
(string-ref str (- (- length start) 1)))
(is-palindrome-helper str (+ start 1) length)
)
)
)
)

(define is-palindrome
(lambda (str)
(is-palindrome-helper
str
0
(string-length str))))

(is-palindrome "racecar")
[/code]
[/quote]

Eww. What do you use to run that? Dr Scheme?
May 14, 2004, 9:27 PM
St0rm.iD
Yup :)
May 15, 2004, 1:13 AM
Mephisto
I hope whoever cares doesn't take Storm's code seriously. :)
May 15, 2004, 1:26 AM
Tuberload
[quote author=Mephisto link=board=30;threadid=6759;start=15#msg60181 date=1084584398]
I hope whoever cares doesn't take Storm's code seriously. :)
[/quote]

Scheme is a programming language...
May 15, 2004, 1:33 AM
Mephisto
Yes, but this is C/C++, not scheme. I seriously doubt he cared about an answer in scheme. :p
May 15, 2004, 2:15 AM
Tuberload
[quote author=Mephisto link=board=30;threadid=6759;start=15#msg60187 date=1084587326]
Yes, but this is C/C++, not scheme. I seriously doubt he cared about an answer in scheme. :p
[/quote]

That was not my point. For people that truly care, maybe they should take his code seriously... A discussion can be spawned from a question. That discussion does not necessarily have to stick with the initial question.

Programming is an art, and a language is a tool.
May 15, 2004, 2:30 AM
Mephisto
*shrug*

I think you're missing the point of a C/C++ programming forum. The one who started the initial question didn't want the code in Scheme, and if they did I'd be suprised. Storm randomly (and probably joking around) posted some code in Scheme. I doubt the one who asked the question would care, especially since they posted this in the C/C++ programming forum, and wanted a C/C++ answer. Who the hell cares about an answer in Scheme at this point? Jeesh...
May 15, 2004, 2:42 AM
Tuberload
[quote author=Mephisto link=board=30;threadid=6759;start=15#msg60189 date=1084588921]
*shrug*

I think you're missing the point of a C/C++ programming forum. The one who started the initial question didn't want the code in Scheme, and if they did I'd be suprised. Storm randomly (and probably joking around) posted some code in Scheme. I doubt the one who asked the question would care, especially since they posted this in the C/C++ programming forum, and wanted a C/C++ answer. Who the hell cares about an answer in Scheme at this point? Jeesh...
[/quote]

Do you even read what is said to you before you reply?
May 15, 2004, 3:34 AM
Mephisto
*shrug*

Must you have to try and argue that someone should really take Storm's code into account when this is a C/C++ board, with a C/C++ question, expecting C/C++ answers and not code from another language? Jeesh...
May 15, 2004, 3:40 AM
vile
Good job, Meph. Your last reply stopped everyone from helping you.
May 15, 2004, 7:36 AM
Tuberload
[quote author=Mephisto link=board=30;threadid=6759;start=15#msg60198 date=1084592417]
*shrug*

Must you have to try and argue that someone should really take Storm's code into account when this is a C/C++ board, with a C/C++ question, expecting C/C++ answers and not code from another language? Jeesh...
[/quote]

I was not attempting to argue with you, I was trying to get a very subtle message acrossed...
May 15, 2004, 9:10 AM
Adron
[quote author=Mephisto link=board=30;threadid=6759;start=15#msg60198 date=1084592417]
*shrug*

Must you have to try and argue that someone should really take Storm's code into account when this is a C/C++ board, with a C/C++ question, expecting C/C++ answers and not code from another language? Jeesh...
[/quote]

As we have previously concluded that this is some kind of homework question, and that we shouldn't provide direct "paste this code into your program" answers to those, what's wrong with his answer?

I like Storm's code. It's one of the "pseudo-code" category answers, except that his code happens to be working in a different language.

Besides, if you want there to be an easier to use answer, you could provide that yourself. This is a really easy question, anyone with some C++ programming experience should be able to write such a program (not one suitable for handing in, but one that works) in 5 minutes. If you want to give the user what he "expects", by all means, go ahead, do it. Don't complain at others who choose to give hints only.


May 15, 2004, 10:33 AM
St0rm.iD
fine...

- for each character 1..n/2 indexed by i in an n-length string s...
- check whether s[i] == s[n-i]
- logical AND with the next character test
May 15, 2004, 1:56 PM
Arta
heh, it's lamda calculus.. that's kinda neat :)
May 15, 2004, 2:28 PM

Search