# Answer to Question #16093 in Delphi | Pascal for patrick

Question #16093

write a program given two lines of words. place in the same queue with words of even length and the other, with the odd, without additional data structures, except a set of variables

Expert's answer

var s1,s2:string;

p1,p2:integer;

begin

& readln(s1);

& readln(s2);

& s1:=' '+s1+' ';

& s2:=' '+s2+' ';

& p2:=pos(' ',s1);

& p1:=0;

& while (p2<length(s1)) do

begin

if odd(length(copy(s1,p1+1,p2-p1-1)))

& then

& begin

s2:=s2+copy(s1,p1+1,p2-p1-1)+' ';

delete(s1,p1+1,p2-p1-1);

p2:=p1;

& end

else

& begin

p1:=p2;

p2:=pos(' ',copy(s1,p1+1,length(s1)-p2+1))+p1;

& end;

end;

& p2:=pos(' ',s2);

& p1:=0;

& while (p2<length(s2)) do

begin

if (not odd(length(copy(s2,p1+1,p2-p1-1))))and(length(copy(s2,p1+1,p2-p1-1))>0)

& then

begin

s1:=s1+copy(s2,p1+1,p2-p1-1)+' ';

delete(s2,p1+1,p2-p1-1);

p2:=p1;

end

& else

begin

p1:=p2;

p2:=pos(' ',copy(s2,p1+1,length(s2)-p2+1))+p1;

end;

end;

writeln(s1);

writeln(s2);

end.

p1,p2:integer;

begin

& readln(s1);

& readln(s2);

& s1:=' '+s1+' ';

& s2:=' '+s2+' ';

& p2:=pos(' ',s1);

& p1:=0;

& while (p2<length(s1)) do

begin

if odd(length(copy(s1,p1+1,p2-p1-1)))

& then

& begin

s2:=s2+copy(s1,p1+1,p2-p1-1)+' ';

delete(s1,p1+1,p2-p1-1);

p2:=p1;

& end

else

& begin

p1:=p2;

p2:=pos(' ',copy(s1,p1+1,length(s1)-p2+1))+p1;

& end;

end;

& p2:=pos(' ',s2);

& p1:=0;

& while (p2<length(s2)) do

begin

if (not odd(length(copy(s2,p1+1,p2-p1-1))))and(length(copy(s2,p1+1,p2-p1-1))>0)

& then

begin

s1:=s1+copy(s2,p1+1,p2-p1-1)+' ';

delete(s2,p1+1,p2-p1-1);

p2:=p1;

end

& else

begin

p1:=p2;

p2:=pos(' ',copy(s2,p1+1,length(s2)-p2+1))+p1;

end;

end;

writeln(s1);

writeln(s2);

end.

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

Assignment Expert10.10.12, 14:26You're welcome. We are glad to be helpful.

If you really liked our service please press like-button beside answer field. Thank you!

patrick09.10.12, 22:06thanks a lot this is so helpful of you

## Leave a comment