Reverse words in a string: Difference between revisions
Content added Content deleted
No edit summary |
(Added solution for Action!) |
||
Line 61: | Line 61: | ||
{{out}} |
{{out}} |
||
<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|Action!}}== |
|||
<lang Action!>PROC Reverse(CHAR ARRAY src,dst) |
|||
BYTE i,j,k,beg,end |
|||
i=1 j=src(0) |
|||
WHILE j>0 |
|||
DO |
|||
WHILE j>0 AND src(j)=$20 |
|||
DO j==-1 OD |
|||
IF j=0 THEN |
|||
EXIT |
|||
ELSE |
|||
end=j |
|||
FI |
|||
WHILE j>0 AND src(j)#$20 |
|||
DO j==-1 OD |
|||
beg=j+1 |
|||
IF i>1 THEN |
|||
dst(i)=$20 i==+1 |
|||
FI |
|||
FOR k=beg TO end |
|||
DO |
|||
dst(i)=src(k) i==+1 |
|||
OD |
|||
OD |
|||
dst(0)=i-1 |
|||
RETURN |
|||
PROC Test(CHAR ARRAY src) |
|||
CHAR ARRAY dst(40) |
|||
Reverse(src,dst) |
|||
PrintE(dst) |
|||
RETURN |
|||
PROC Main() |
|||
Test("---------- Ice and Fire ------------") |
|||
Test("") |
|||
Test("fire, in end will world the say Some") |
|||
Test("ice. in say Some") |
|||
Test("desire of tasted I've what From") |
|||
Test("fire. favor who those with hold I") |
|||
Test("") |
|||
Test("... elided paragraph last ...") |
|||
Test("") |
|||
Test("Frost Robert -----------------------") |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Reverse_words_in_a_string.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
<pre> |
||
------------ Fire and Ice ---------- |
------------ Fire and Ice ---------- |