Computer Science Canada middle letter? |
Author: | pokerface [ Tue Oct 26, 2004 4:12 pm ] |
Post subject: | middle letter? |
im having problems getting any idea on how to get the middle letter of a word! example: MONKEY then middle letter is none cause its even Madam then middle letter is d i have no idea on how to get that to work! could u give me some idea on how to start it? |
Author: | Tony [ Tue Oct 26, 2004 5:05 pm ] | ||
Post subject: | |||
|
Author: | pokerface [ Tue Oct 26, 2004 5:13 pm ] | ||
Post subject: | |||
it dont work cause i took out round and now its not working? what may be the problem? |
Author: | templest [ Tue Oct 26, 2004 5:35 pm ] | ||
Post subject: | |||
|
Author: | pokerface [ Tue Oct 26, 2004 7:15 pm ] |
Post subject: | |
that doesnt work thou? what was that any ways? |
Author: | AsianSensation [ Tue Oct 26, 2004 7:48 pm ] |
Post subject: | |
yeah, it was templest's attempt at helping. to get the middle letter, do a simple if statement, if length (word) mod 2 = 0 then there is no middle letter, because it's even. else, the middle letter is word (length (word) div 2 + 1), because length div 2 rounds down, add 1 to it because the substring starts with 1 as the index (I think that made sense....) |
Author: | pokerface [ Tue Oct 26, 2004 8:23 pm ] | ||||
Post subject: | |||||
thanks but i did what u said! im getting better at this! hehe! but i am getting an error with this program
could u see what may be changed to make it work this line is the one giving me the most problems
|
Author: | AsianSensation [ Tue Oct 26, 2004 8:37 pm ] | ||
Post subject: | |||
well, I see you are trying to replace a substring with another substring, well, do something like this: find the location of the substring in the original string using index, then sandwich the new substring with all the stuff before and after the original substring. Confused? Good, here is an example:
This is one of the easier approach, because it doesn't solve multiple occurences. Think on it first, then make your own. |
Author: | templest [ Wed Oct 27, 2004 6:52 am ] |
Post subject: | |
wtf? How the hell does that no work? I just ran it on my box right now without any problems. Do you have turing 4.0.5? My code works, you pinko commie. It was a joke too. Mine does the exact same thing that tony's does, only that with 15 lines of useless code. ![]() |
Author: | wtd [ Wed Oct 27, 2004 10:08 pm ] | ||
Post subject: | |||
I have no idea why this is such a controversial topic.
Oh, and Templest... throwing around unnecessary insults doesn't help anything. |