Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

151. Reverse Words in a String #12

Open
Azureki opened this issue Oct 8, 2018 · 1 comment
Open

151. Reverse Words in a String #12

Azureki opened this issue Oct 8, 2018 · 1 comment

Comments

@Azureki
Copy link
Owner

Azureki commented Oct 8, 2018

鬼知道要求是什么。

Input: "hi!"
Output: "!hi"
Expected: "hi!"

看到这个,以为意思是最后可能会有!,所以要考虑这种情况。

Input: "+---...2x+--x--+x-+-x2...---+"
Output: "x-+-x+--x--+x2...---+2...---+"
Expected: "+---...2x+--x--+x-+-x2...---+"

看到这个,我以为是不能用先reverse()整体,再reverse每个单词的方法了。因为符号的顺序就反了。

……

期间还有遇到数字考虑要不要分析的。

我最后才意识到,似乎就是把空格和非空格区别一下就行了。以空格进行split(),分出来的就是words,哪怕标点符号也是words

@Azureki
Copy link
Owner Author

Azureki commented Oct 8, 2018

我最终的cpp略复杂。

简单解法以及多种解法参见这里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant