Reverse words in a string: Difference between revisions

no edit summary
No edit summary
Line 1,780:
ok
</pre>
 
=={{header|Pascal}}==
Free Pascal 3.0.0
<lang pascal>program Reverse_words(Output);
{$H+}
 
const
nl = chr(10); // Linefeed
sp = chr(32); // Space
TXT =
'---------- Ice and Fire -----------'+nl+
nl+
'fire, in end will world the say Some'+nl+
'ice. in say Some'+nl+
'desire of tasted I''ve what From'+nl+
'fire. favor who those with hold I'+nl+
nl+
'... elided paragraph last ...'+nl+
nl+
'Frost Robert -----------------------'+nl;
 
var
I : integer;
ew, lw : ansistring;
c : char;
 
function addW : ansistring;
var r : ansistring = '';
begin
r := ew + sp + lw;
ew := '';
addW := r
end;
 
begin
ew := '';
lw := '';
 
for I := 1 to strlen(TXT) do
begin
c := TXT[I];
case c of
sp : lw := addW;
nl : begin writeln(addW); lw := '' end;
else ew := ew + c
end;
end;
readln;
end.</lang>
{{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|Perl}}==
164

edits