Reverse words in a string: Difference between revisions
Content added Content deleted
(Simplified C#) |
No edit summary |
||
Line 1,855: | Line 1,855: | ||
''Note:'' With the technique used here for splitting <code>s</code> into lines (not part of the task) the last line will be gobbled up if it does not end with a newline. |
''Note:'' With the technique used here for splitting <code>s</code> into lines (not part of the task) the last line will be gobbled up if it does not end with a newline. |
||
=={{header|Maple}}== |
|||
<lang Maple>while (true) do |
|||
input := readline("input.txt"): |
|||
if input = 0 then break: fi: |
|||
input := StringTools:-Trim(input): # remove leading/trailing space |
|||
input := StringTools:-Join(ListTools:-Reverse(StringTools:-Split(input, " "))," "): |
|||
printf("%s\n", input): |
|||
od:</lang> |
|||
{{Out|Output}} |
|||
<pre>------------ Fire and Ice ---------- |
|||
Some say the world will end in fire, |
|||
Some say in ice. |
|||
From what I've tasted of desire |
|||
I hold with those who favor fire. |
|||
... last paragraph elided ... |
|||
----------------------- Robert Frost</pre> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |