比赛 |
NOIP_5 |
评测结果 |
WWWWW |
题目名称 |
添加号 |
最终得分 |
0 |
用户昵称 |
maxiem |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-24 21:48:23 |
显示代码纯文本
program exam4;
var
s:string;
a:array [1..21] of string[100];
min,sum:array [0..101] of byte;
now,i,j,k,m,n,l:byte;
procedure increase;
var
i,j,tmp,code:integer;
begin
for i:=1 to m+1 do begin
for j:=length(a[i]) downto 1 do begin
val(a[i][j],tmp,code);
if sum[0]<length(a[i])-j+1 then begin
inc(sum[0]);
sum[sum[0]]:=tmp;
end
else begin
sum[length(a[i])-j+1]:=sum[length(a[i])-j+1]+tmp;
if sum[length(a[i])-j+1]>9 then begin
sum[length(a[i])-j+1]:=sum[length(a[i])-j+1]-10;
sum[length(a[i])-j+2]:=sum[length(a[i])-j+2]+1;
if sum[0]<length(a[i])-j+2 then sum[0]:=sum[0]+1;
end;
end;
end;
end;
end;
begin
assign (input,'exam4.in');
reset (input);
readln (s);
readln (m);
close (input);
assign (output,'exam4.out');
rewrite (output);
l:=length(s);n:=l div m;
for i:=1 to m+1 do begin
for j:=1 to 21 do a[j]:='';
now:=1;
for j:=1 to m+1 do if i=j then begin
for k:=1 to n*(m+1)-l do a[j]:=a[j]+'0';
a[j]:=a[j]+copy(s,now,l-n*m);
inc(now,l-n*m);
end
else begin
a[j]:=copy(s,now,n);
inc(now,n);
end;
fillchar (sum,sizeof(sum),0);
increase;
if min[0]=0 then min:=sum;
if sum[0]<min[0] then min:=sum else begin
for j:=sum[0] downto 1 do if min[j]>sum[j] then begin
min:=sum;
break;
end
else break;
end;
end;
for i:=sum[0] downto 1 do write (min[i]);
writeln;
close (output);
end.