|
|
back to boardWhere is wrong? Posted by msi 25 Apr 2003 13:12 var s,s2: string; k,i,l,Ls,j: longint; a: boolean; begin repeat s:=''; s2:=''; k:=1; j:=0; readln(s2); s:=s2; Ls:=length(s2); if (Ls>0) and (s<>' ') then repeat if (k-1)<=Ls then begin a:=false; l:=k; repeat if ((s[k]<='z') and (s[k]>='a')) or ((s[k]<='Z') and (s[k] >='A')) or (s[k]='-') then k:=k+1 else a:=true; until a or (k>Ls); for i:=k-1 downto l do begin if s[i]<>'-' then begin j:=j+1; write(s[i]); end; end; if j<Ls then begin repeat write(s[k]); j:=j+1; k:=k+1; until ((s[k]<='z') and (s[k]>='a')) or ((s[k]<='Z') and (s[k] >='A')) or (j>=Ls); end; end; until k>=Ls; until eof; end. have you noticed about last word? which may not ended by space? (-) > var > s,s2: string; > k,i,l,Ls,j: longint; > a: boolean; > begin > repeat > s:=''; > s2:=''; > k:=1; > j:=0; > readln(s2); > s:=s2; > Ls:=length(s2); > if (Ls>0) and (s<>' ') then > repeat > if (k-1)<=Ls then begin > a:=false; > l:=k; > repeat > if ((s[k]<='z') and (s[k]>='a')) or ((s[k]<='Z') and (s [k] > >='A')) or (s[k]='-') then k:=k+1 else a:=true; > until a or (k>Ls); > > for i:=k-1 downto l do > begin > if s[i]<>'-' then begin j:=j+1; write(s[i]); end; > end; > > if j<Ls then begin > repeat > write(s[k]); > j:=j+1; > k:=k+1; > until ((s[k]<='z') and (s[k]>='a')) or ((s[k]<='Z') and (s[k] > >='A')) or (j>=Ls); > end; end; > > until k>=Ls; > until eof; > end. |
|
|