记录编号 |
2715 |
评测结果 |
AAAAA |
题目名称 |
[NOI 1996]添加号 |
最终得分 |
100 |
用户昵称 |
francis |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
2.961 s |
提交时间 |
2008-09-25 12:38:34 |
内存使用 |
7.35 MiB |
显示代码纯文本
program exam4;
const
fin='exam4.in';
fou='exam4.out';
var
num:array[1..300]of longint;
a:array[1..300]of longint;
b:array[1..300]of longint;
f:array[0..20,1..300,1..300]of longint;
ll:array[0..20,1..300]of longint;
lll,q,long,p,l,i,j,m:longint;
st:string;
bo,boo:boolean;
f1,f2:text;
procedure init;
begin
assign(f1,fin); assign(f2,fou);
reset(f1); rewrite(f2);
readln(f1,st);
read(f1,m);
l:=length(st);
for i:=1 to l do
num[i]:=ord(st[i])-48;
for i:=1 to l do
for j:=1 to i do
begin
f[0,i,j]:=num[j];
ll[0,i]:=i;
end;
for i:=1 to m do
for j:=1 to l do
ll[i,j]:=300;
end;
procedure jia(i,j:longint);
var
p,k,l1,l2:longint;
c:array[1..300]of longint;
begin
fillchar(c,sizeof(c),0);
l1:=ll[i,j]; l2:=long;
for p:=l1 downto 1 do c[l1+1-p]:=f[i,j,p];
if l1<l2 then lll:=l2 else lll:=l1;
k:=0;
for i:=1 to lll do
begin
b[i]:=c[i]+a[i]+k;
k:=b[i] div 10;
b[i]:=b[i] mod 10;
end;
if k>0 then begin inc(lll); b[lll]:=1; end;
end;
procedure compare(i,j:longint);
var
t1,t2,l1,l2,p:longint;
c:array[1..300]of longint;
begin
bo:=false;
l1:=ll[i,j]; l2:=lll;
for p:=l1 downto 1 do c[l1+1-p]:=f[i,j,p];
if l1>l2 then begin boo:=true; exit; end;
if l2>l1 then begin boo:=false; exit; end;
if l1=l2 then
begin
t1:=l1; t2:=l2;
while (t1>0)and(c[t1]=b[t2]) do
begin dec(t1); dec(t2); end;
if t1=0 then boo:=true
else begin
if c[t1]>b[t1] then boo:=true;
if c[t1]<b[t1] then boo:=false;
end;
end;
end;
begin
init;
for i:=1 to m do
for j:=i+1 to l do
for p:=i to j-1 do
if num[p+1]<>0 then
begin
long:=0; fillchar(a,sizeof(a),0);
for q:=j downto p+1 do
begin
inc(long); a[long]:=num[q];
end;
jia(i-1,p);
compare(i,j);
if (bo=false)and(boo=true) then
begin
ll[i,j]:=lll;
for q:=lll downto 1 do
f[i,j,lll+1-q]:=b[q];
end;
end;
if ll[m,l]=300 then write(f2,0)
else
for i:=1 to ll[m,l] do
write(f2,f[m,l,i]);
close(f1); close(f2);
end.