Reverse a few words


(Chris) #1

Hi all,

I would like to reverse a few words and print them out. For example:

olleH, woh era uoy
Hello, how are you

What’s the best way to accomplish this?


( Kvaz1r) #2

Hi.
How define which ones should be reversed?


(Chris) #3

They all should be reversed. The word should be… not the sentence. Almost, like letter shifting.


(Lutz Horn) #4

Have you tried anything in Go to achieve this? We could write this code for you but you learn more if you try to solve the problem first. We will be glad to help you with any problems if we see that you have tried.

Some hints:

  • think about what could be a word boundary
  • split the input on word boundaries to get words
  • reverse each word
  • output the reversed word followed by the boundary

This is not the easiest problem but doably. Try!


( Kvaz1r) #5

ahh, right. Your words about a few confused me :slight_smile:

You can easily achieve it with methods from strings package.