呵呵,这题的标签。。。

评测结果

编译成功

Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
foo.pas(2,21) Note: Local variable "k" not used
foo.pas(2,23) Note: Local variable "m" not used
foo.pas(2,25) Note: Local variable "n" not used
foo.pas(3,5) Note: Local variable "h" not used
Linking foo.exe
130 lines compiled, 0.1 sec , 31952 bytes code, 1644 bytes data
4 note(s) issued
测试数据 #0: Accepted, time = 15 ms, mem = 676 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 680 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #6: Accepted, time = 15 ms, mem = 680 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 676 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #10: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #11: Accepted, time = 0 ms, mem = 680 KiB, score = 10
测试数据 #12: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #13: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #14: Accepted, time = 15 ms, mem = 676 KiB, score = 10
测试数据 #15: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #16: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #17: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #18: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #19: Accepted, time = 0 ms, mem = 680 KiB, score = 10
测试数据 #20: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #21: Accepted, time = 0 ms, mem = 680 KiB, score = 10
测试数据 #22: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #23: Accepted, time = 15 ms, mem = 676 KiB, score = 10
测试数据 #24: Accepted, time = 0 ms, mem = 680 KiB, score = 10
测试数据 #25: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #26: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #27: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #28: Accepted, time = 46 ms, mem = 676 KiB, score = 10
测试数据 #29: Accepted, time = 15 ms, mem = 680 KiB, score = 10
测试数据 #30: Accepted, time = 15 ms, mem = 676 KiB, score = 10
测试数据 #31: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #32: Accepted, time = 15 ms, mem = 680 KiB, score = 10
测试数据 #33: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #34: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #35: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #36: Accepted, time = 0 ms, mem = 676 KiB, score = 10
测试数据 #37: Accepted, time = 0 ms, mem = 672 KiB, score = 10
测试数据 #38: Accepted, time = 15 ms, mem = 676 KiB, score = 10
测试数据 #39: Accepted, time = 15 ms, mem = 676 KiB, score = 10
Accepted, time = 196 ms, mem = 680 KiB, score = 400
贴个代码
var s,t,q,p,ans,v,z,da,u:string;
a,b,c,d,e,g,i,j,k,m,n,ji:longint;
h:array[1..200]of boolean;
f:array[1..256]of string;
function qian(l:string):string; //(求一个数的前面一个数,即a-1)
var o,w:longint;r:string;
begin
o:=length(l);
r:=l;
while r[o]='0' do dec(o);
r[o]:=pred(r[o]);
for w:=o+1 to length(r) do r[w]:='9';
if r[1]='0' then delete(r,1,1);
qian:=r;
end;
function hou(l:string):string;//(后一个数,即a+1)
var o,w:longint;r:string;
begin
o:=length(l);
r:=l;
while (r[o]='9')and(o>1) do dec(o);
if (o=1)and(r[1]='9') then
r:='1'+r else r[o]:=succ(r[o]);
for w:=o+1 to length(r) do r[w]:='0';
hou:=r;
end;
function sum(l1,w1:string):string;//(求两数之和)
var o,r,e1:longint;l,w,x:string;
begin
l:=l1;w:=w1;
x:='';
if length(l)<length(w) then
for o:=length(l)+1 to length(w) do l:='0'+l;
if length(l)>length(w) then
for o:=length(w)+1 to length(l) do w:='0'+w;
e1:=0;
for o:=length(w) downto 1 do
begin
r:=ord(l[o])+ord(w[o])-96+e1;
e1:=r div 10;
r:=r mod 10;
x:=chr(r+48)+x;
end;
if e1>0 then x:=chr(e1+48)+x;
sum:=x;
end;
begin
readln(s);
g:=length(s);
f[1]:='9';v:='9';
for i:=2 to 256 do
begin
v:=sum(v,'9');
f[i]:=v;
for j:=1 to i-1 do f[i]:=f[i]+'0';
end;
ans:='';
for i:=1 to 250 do ans:=ans+'0';
c:=1;
for i:=1 to length(s) do if s[i]<>'0' then begin c:=0;break;end;
if c=1 then begin ji:=1;ans:='1'+s;e:=length(ans)-1;end;//末尾全是0时特殊判断
if ji=0 then
for i:=1 to g do
begin
for j:=1 to g-i+1 do
begin
if s[j]='0' then continue;
t:=copy(s,j,i);a:=j-1;b:=j+i;
q:=t;p:=t;
while a>0 do begin q:=qian(q);
if length(q)>a then begin t:=copy(q,length(q)-a+1,a)+t;a:=0;end else
begin t:=q+t;a:=a-length(q);
if q='0' then continue;end;end;
while b<=g do begin p:=hou(p);
if length(p)>g-b+1 then begin t:=t+copy(p,1,g-b+1);b:=g+1;end else
begin t:=t+p;b:=b+length(p);end;end;
if t=s then begin ans:=copy(s,j,i);e:=j+i-1;break;end;
end;
if e>0 then break;
end;

if ji=0 then
for i:=2 to g do
begin
for j:=g downto g-i+2 do
if j-i<=0 then
begin
if s[j]='0' then continue;
t:=copy(s,j,g-j+1);
p:=copy(s,g-i+1,j-g+i-1);
q:=hou(p);
if length(q)>length(p) then
begin t:=t+copy(q,2,length(q)-1);end else t:=t+q;
c:=0;
p:=qian(t);
if copy(p,length(p)-j+2,length(p))=copy(s,1,j-1) then c:=1;
if c=0 then continue;
if length(t)<length(ans) then c:=0 else
if length(t)=length(ans) then begin if t<ans then c:=0;end else
continue;
if c=0 then begin ans:=t;e:=j-1+length(t);end;
end;
end;
if ji=0 then begin
da:='0';
ans[1]:=pred(ans[1]);
ans:=sum(ans,'1');
da:=ans;
u:='0';
for i:=1 to length(ans)-1 do u:=sum(u,f[i]);
for i:=1 to length(ans)-1 do
da:=sum(da,ans);
da:=sum(da,u);
end else
begin
da:='0';
for i:=1 to e do da:=sum(da,f[i]);
end;
if ji=0 then begin
if length(da)<6 then
begin z:=da;da:='';end else
begin z:=copy(da,length(da)-5,6);delete(da,length(da)-5,6);end;
val(z,d);
d:=d-e;
str(d,z);
da:=da+z;
end;
da:=sum(da,'1');
if ji=1 then da:=sum(da,'1');
writeln(da);
end.

9 条评论

  • 1

信息

ID
1005
难度
8
分类
字符串 | KMP 点击显示
标签
(无)
递交数
6710
已通过
634
通过率
9%
被复制
33
上传者