Guest User

Untitled

a guest
Dec 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.83 KB | None | 0 0
  1. program h1;
  2. var
  3.   n,m,p,i : integer;
  4.   a,b,c,d,e : byte;
  5. begin
  6.   ReadLn(n);
  7.  
  8.   for i:=1 to n do
  9.   begin
  10.     a:=i mod 10;
  11.     b:=(i mod 100) div 10;
  12.     c:=(i mod 1000) div 100;
  13.     d:=(i mod 10000) div 1000;
  14.     e:=i div 10000;
  15.    
  16.     if (e>0) and (d>0) and (c>0) and (b>0) and (a>0) then m:=10000*a + 1000*b + 100*c + 10*d + e
  17.     else if (e=0) and (d>0) and (c>0) and (b>0) and (a>0) then m:=1000*a + 100*b + 10*c + d
  18.     else if (e=0) and (d=0) and (c>0) and (b>0) and (a>0) then m:=100*a + 10*b + c
  19.     else if (e=0) and (d=0) and (c=0) and (b>0) and (a>0) then m:=10*a + b
  20.     else if (e=0) and (d=0) and (c=0) and (b=0) and (a>0) then m:=i
  21.     else m:=0;
  22.    
  23.     if (m<=n) and (m>0) then
  24.     begin
  25.       Inc(p);
  26.       WriteLn(i, '=',e,d,c,b,a, ' : ', m);
  27.     end;
  28.   end;
  29.  
  30.   WriteLn('Turnbacks: ', p);
  31. end.
Add Comment
Please, Sign In to add comment