unit my_unit5; interface function func1_1(s: string): string; function func1_2(s: string): string; function func1_3(s: string): string; function func2(s: string): string; function func3(s: string): string; function num_of_words(s: string): byte; implementation function func1_1(s: string): string; begin while (s[1]=' ')and(length(s)>0) do delete(s,1,1); func1_1:=s; end; function func1_2(s: string): string; begin while s[length(s)]=' ' do delete(s,length(s),1); func1_2:=s; end; function func1_3(s: string): string; begin s:=func1_1(s); s:=func1_2(s); func1_3:=s; end; function func2(s: string): string; var i: byte; begin s:=func1_1(s); s:=func1_2(s); i:=1; while i<length(s) do if (s[i]=' ')and(s[i+1]=' ') then delete(s,i,1) else inc(i); func2:=s; end; function func3(s: string): string; var i: byte; begin i:=1; while i<=length(s) do if s[i]=' ' then delete(s,i,1) else inc(i); func3:=s; end; function num_of_words(s: string): byte; var i,n: byte; begin s:=func2(s); n:=0; for i:=1 to length(s) do if s[i]=' ' then inc(n); if length(s)>0 then num_of_words:=n+1 else num_of_words:=0; end; begin end. |