Guest User

Untitled

a guest
Oct 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.29 KB | None | 0 0
  1. var
  2. i,j,k,g,h,n,m,ltest,rtest,l,r:longint;
  3. a,ish:array[0..19] of shortint;
  4. s:string;
  5.  
  6. function test:boolean;
  7. begin
  8.  ltest:=1;
  9.  rtest:=n;
  10.  while (a[ltest]=a[rtest])and(ltest<rtest) do
  11.  begin
  12.   inc(ltest);
  13.   dec(rtest);
  14.  end;
  15.  if ltest>=rtest then test:=true
  16.   else test:=false;
  17. end;
  18.  
  19. procedure print;
  20. var id:integer;
  21. begin
  22.  for id:=1 to n-1 do write(a[id]);
  23.  writeln(a[n]);
  24. end;
  25.  
  26. procedure next(poz:integer);
  27. var th:integer;
  28. begin
  29.  while a[poz]<>a[n-poz+1] do
  30.   begin
  31.    inc(a[poz]);
  32.    for th:=poz downto 1 do
  33.     if a[th]>9 then
  34.      begin
  35.       a[th-1]:=a[th-1]+a[th]-9;
  36.       a[th]:=0;
  37.       if (th)<=(n div 2) then
  38.        a[n-th+1]:=a[th];
  39.      end else break;
  40.   end;
  41. end;
  42.  
  43. begin
  44.  
  45.  readln(s);
  46.  n:=length(s);
  47.  for i:=1 to n do
  48.   begin
  49.   a[i]:=ord(s[i])-ord('0');
  50.   ish[i]:=a[i];
  51.   end;
  52.  if n=1 then
  53.   begin
  54.    if a[1]<=8 then
  55.    begin
  56.     writeln(a[1]+1);
  57.     halt;
  58.    end;
  59.    if a[1]=9 then
  60.     begin
  61.      writeln(11);
  62.      halt;
  63.     end;
  64.   end;
  65. h:=n;
  66. if test then
  67. begin
  68.  while a[h]>=9 do
  69.   begin
  70.    a[h]:=a[h]-9;
  71.    dec(h);
  72.   end;
  73. inc(a[h]);
  74.  if h=0 then
  75.   begin
  76.   for h:=n downto 0 do
  77.    a[h+1]:=a[h];
  78.  inc(n);
  79.  end;
  80. end;
  81. l:=1;
  82. r:=n;
  83. if n mod 2 = 0 then
  84.  h:=n div 2 + 1 else
  85.  h:=n div 2 + 2;
  86. for g:=n downto h do next(g);
  87. print;
  88. end.
Add Comment
Please, Sign In to add comment