# Answer to Question #7842 in Delphi | Pascal for pit

Question #7842

help me with this problem:given a string of symbols seperated by space and ending with a point,print the symbols which are different from the last symbol and delete the symbol with the maximum length.

Expert's answer

program Prog;

var

& s, s1, sf: String;

& i, len:integer;

& f: boolean;

begin

& writeln('Write your string:');

& readln(s);

& if pos(' ', s)=0 then writeln('.') else

& begin

i := length(s)-1;

s1:='';

while s[i]<>' ' do

begin

s1 := s[i] + s1;

dec(i);

end;

f := true;

sf:='';

while f do

begin

if s1 = copy(s,1,pos(' ', s)-1) then

else

begin

& sf:=sf+copy(s,1,pos(' ', s));

end;

delete(s,1,pos(' ', s));

if pos(' ', s)=0 then f:= false;

end;

sf:=sf+s;

len := 0;

f:=true;

s:=sf;

while f do

begin

if ((pos(' ',s)-1)>len)then len:=pos(' ',s)-1;

delete(s,1,pos(' ', s));

if pos(' ', s)=0 then f:= false;

end;

if ((length(s)-1) > len) then

begin

writeln(copy(sf,1,pos(s,sf)-2),'.');

end else

begin

f:=true;

s:=sf;

sf:='';

while f do

begin

& if ((pos(' ',s)-1)=len)then

& else

sf:=sf+copy(s,1,pos(' ', s));

& delete(s,1,pos(' ', s));

& if pos(' ', s)=0 then f:= false;

end;

if (length(s)-1)=len then

begin

& if sf<>'' then sf[length(sf)] := '.' else sf:='.';

end

else sf:=sf+s;

writeln(sf);

end;

& end;

end.& &

var

& s, s1, sf: String;

& i, len:integer;

& f: boolean;

begin

& writeln('Write your string:');

& readln(s);

& if pos(' ', s)=0 then writeln('.') else

& begin

i := length(s)-1;

s1:='';

while s[i]<>' ' do

begin

s1 := s[i] + s1;

dec(i);

end;

f := true;

sf:='';

while f do

begin

if s1 = copy(s,1,pos(' ', s)-1) then

else

begin

& sf:=sf+copy(s,1,pos(' ', s));

end;

delete(s,1,pos(' ', s));

if pos(' ', s)=0 then f:= false;

end;

sf:=sf+s;

len := 0;

f:=true;

s:=sf;

while f do

begin

if ((pos(' ',s)-1)>len)then len:=pos(' ',s)-1;

delete(s,1,pos(' ', s));

if pos(' ', s)=0 then f:= false;

end;

if ((length(s)-1) > len) then

begin

writeln(copy(sf,1,pos(s,sf)-2),'.');

end else

begin

f:=true;

s:=sf;

sf:='';

while f do

begin

& if ((pos(' ',s)-1)=len)then

& else

sf:=sf+copy(s,1,pos(' ', s));

& delete(s,1,pos(' ', s));

& if pos(' ', s)=0 then f:= false;

end;

if (length(s)-1)=len then

begin

& if sf<>'' then sf[length(sf)] := '.' else sf:='.';

end

else sf:=sf+s;

writeln(sf);

end;

& end;

end.& &

## Comments

Assignment Expert30.03.12, 13:19You're welcome! We are glad to be helpful.

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

peter29.03.12, 23:03this is awesome.thanks alot!

## Leave a comment