Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- i,j,k,g,h,n,m,ltest,rtest,l,r:longint;
- a,ish:array[0..19] of shortint;
- s:string;
- function test:boolean;
- begin
- ltest:=1;
- rtest:=n;
- while (a[ltest]=a[rtest])and(ltest<rtest) do
- begin
- inc(ltest);
- dec(rtest);
- end;
- if ltest>=rtest then test:=true
- else test:=false;
- end;
- procedure print;
- var id:integer;
- begin
- for id:=1 to n-1 do write(a[id]);
- writeln(a[n]);
- end;
- procedure next(poz:integer);
- var th:integer;
- begin
- while a[poz]<>a[n-poz+1] do
- begin
- inc(a[poz]);
- for th:=poz downto 1 do
- if a[th]>9 then
- begin
- a[th-1]:=a[th-1]+a[th]-9;
- a[th]:=0;
- if (th)<=(n div 2) then
- a[n-th+1]:=a[th];
- end else break;
- end;
- end;
- begin
- readln(s);
- n:=length(s);
- for i:=1 to n do
- begin
- a[i]:=ord(s[i])-ord('0');
- ish[i]:=a[i];
- end;
- if n=1 then
- begin
- if a[1]<=8 then
- begin
- writeln(a[1]+1);
- halt;
- end;
- if a[1]=9 then
- begin
- writeln(11);
- halt;
- end;
- end;
- h:=n;
- if test then
- begin
- while a[h]>=9 do
- begin
- a[h]:=a[h]-9;
- dec(h);
- end;
- inc(a[h]);
- if h=0 then
- begin
- for h:=n downto 0 do
- a[h+1]:=a[h];
- inc(n);
- end;
- end;
- l:=1;
- r:=n;
- if n mod 2 = 0 then
- h:=n div 2 + 1 else
- h:=n div 2 + 2;
- for g:=n downto h do next(g);
- print;
- end.
Add Comment
Please, Sign In to add comment