- 超长数字串
- 2014-12-21 16:15:00 @
标签错误,呵呵,误导。。。。。。。。。。。。。。。。。
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;
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;
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;
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.
10 条评论
-
doc LV 10 MOD @ 2015-01-15 19:34:30
下次请发到题解中去,不要发在讨论中。
此外,对于程序又不优美,可读性差,还没有注解的程序,我不认为算作什么题解。起码如果我不会做这一题,看了你的程序也依然还是不会做。 -
2015-01-14 20:43:44@
畜生,继续顶
-
2015-01-14 20:04:53@
上去
-
2015-01-14 20:02:54@
顶起来
-
2014-12-24 20:56:17@
顶顶
-
2014-12-24 20:55:08@
。。无聊
-
2014-12-24 18:54:01@
靠靠靠
-
2014-12-21 16:25:56@
我们就要回来了
-
2014-12-21 16:25:36@
hai
-
2014-12-21 16:15:18@
闷骚
- 1