Pagini recente » Cod sursa (job #941149) | Cod sursa (job #3036627) | Cod sursa (job #1572016) | Cod sursa (job #721696) | Cod sursa (job #303054)
Cod sursa(job #303054)
var v:array[1..100] of string;
c:char; f,g:text; q,sp2,max,i,j,cuv,s,sp,con:longint;
begin
assign(f,'text.in'); reset(f);
assign(g,'text.out'); rewrite(g);
readln(f,max);
con:=0;
while not eoln (f) do begin
read(f,c);
if (c in ['a'..'z']) or (c in ['A'..'Z']) then begin
inc(con);
while (c in ['a'..'z']) or (c in ['A'..'Z']) do begin
v[con]:=v[con]+c; read(f,c);
end;
end;
end;
i:=1;
while i<=con do begin
sp:=0;
s:=length(v[i]); cuv:=1;
while (s<=max) and (i+cuv-1<=con) do begin
inc(cuv); s:=s+1+length(v[i+cuv-1]);
end;
s:=s-length(v[i+cuv-1])-1;
dec(cuv);
sp:=0; sp2:=0;
if cuv>1 then sp:=(max-s) div (cuv-1);
if cuv>1 then sp2:=(max-s) mod (cuv-1);
for j:=i to i+cuv-2 do begin
write(g,v[i],' ');
for q:=1 to 1+sp+sp2-1 do write(g,' ');
if sp2>1 then dec(sp2);
end;
writeLN(g,v[i+cuv-1]);
I:=I+CUV;
end;
close(g);
end.