okay, i've been looking for a nice algorithm for this one for a long time, all i find are cpp, java and c# code. i've been trying to reverse the order of each word in its place, but i don't seem to be able to do so. i tried with two strings, swapping the chars of each word but it simply didn't work...
this is my...attempt to write each word backwards...
program stringzorz;
var
s1, s2 : string;
i, j ,k, start, endd : integer;
procedure swp(var c1, c2 : char);
var p : char;
begin
p := c1;
c1 := c2;
c2 := p;
end;
begin
readln(s1);
s2 := s1;
endd := 1;
i := 1;
while i < length(s1) do
begin
while s1[i] <> ' ' do
i:= i + 1;
start := i;
j := i;
for i := endd to start do
begin
swp(s1[i], s2[j]);
j := j - 1;
end;
end;
writeln(s1);
end.
i know it's all...scrambled, i'm not that good at the esthetic part of coding but could someone please give me an idea atleast?