How to reverse a chain of characters?

后端 未结 5 1610
野的像风
野的像风 2021-01-24 18:24

I have to create a program that reverses phrases.

For example: when I write hello guys, I want syug olleh

This is what

5条回答
  •  忘了有多久
    2021-01-24 19:11

    Here's a shorter way to do it:

    forall (i=1:len(string)) string(i:i) = string(len(string)-i+1:len(string)-i+1)
    

    It even saves a handful of bytes ! I'm not sure I'd suggest this was more intelligent though.

提交回复
热议问题