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.
1
Expert's answer
2012-03-29T11:07:27-0400
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.& &

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
30.03.12, 13:19

You're welcome! We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!

peter
29.03.12, 23:03

this is awesome.thanks alot!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS