×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need help for a beginner :)

Need help for a beginner :)

Need help for a beginner :)

(OP)
Hi all. I can't figure out how to do this:
I have a String e.g. '1 2  3   4    '
I need to get this:   '4 3  2   1    '
Or i have:           ' one  two   three    four'
Need to get this: ' four  three   two    one'
And I need to do that WITHOUT arrays o.O
Any ideas?

RE: Need help for a beginner :)

to get help, you'd better convince people this isn't homework. It's a standard exercise set at the begining of many courses, and it's the time of year when many courses are just begining.

RE: Need help for a beginner :)

Hi

I agree with lionelhill, this quite smells like homework. However an interesting one, given the spaces which seems to need to be preserved.

CODE --> pseudocode

// set the reversed string to the original, but replace the groups of non-space characters with placeholders, for example $
original := ' one  two   three    four'
reversed := ' $  $   $    $'

currently_in_a_word := no // in original we are inside a group of non-space characters
current_placeholder := 0 // in reversed this is the current place_holder position
loop backward through original character by character
  current_character := original's current character
  if current_character is a space
    if currently_in_a_word
      currently_in_a_word := no
    end if
  else // not a space
    if not currently_in_a_word // first character of a non-space group
      currently_in_a_word := yes
      advance current_placeholder to the next one
      remove the placeholder character at current_placeholder
    end if
    insert current_character in reversed at current_placeholder
  end if
end loop

Feherke.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close