1 / 9

2011-2012 集训队第一次集中学习

2011-2012 集训队第一次集中学习. 进制转换. repeat i: = i +1; y mod x 的余数──→ a[i] ) y := y div x Until y=0. 要考虑的问题,如果是10以上的进制,余数有可能是2位数. program ex; var n,nx:real; nz:integer; procedure changez(nz:integer); var x:integer; begin x:=nz mod 2; nz:=nz div 2;

ophrah
Download Presentation

2011-2012 集训队第一次集中学习

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2011-2012集训队第一次集中学习 进制转换

  2. repeat i:=i+1; y mod x 的余数──→ a[i]) y:= y div x Until y=0 要考虑的问题,如果是10以上的进制,余数有可能是2位数

  3. program ex; var n,nx:real; nz:integer; procedure changez(nz:integer); var x:integer; begin x:=nz mod 2; nz:=nz div 2; if nz<>0 then changez(nz); write(x); end; procedure changex(nx:real); var i,t:integer; begin for i:=1 to 5 do begin nx:=nx*2; t:=trunc(nx); write(t); nx:=nx-t; end; end; begin readln(n); nz:=trunc(n); nx:=n-nz; changez(nz); write('.'); changex(nx); end.

  4. procedure changex(t:integer); var i,j,q,x:integer; begin for i:=1 to 5 do begin q:=0; for j:=1 to len2 do begin x:=b[j]*2+q; q:=x div 10; b[j]:=x mod 10; end; write(q); end; end; program zh_10_2; const w=5; var st,st1,st2:string; a,b,c:array[0..1000] of integer; p,len,len1,len2,i:integer; procedure changez(t:integer); var i,j,x:integer; begin j:=0; while t<>0 do begin inc(j); x:=0; for i:= t downto 1 do begin a[i]:=x*10+a[i]; x:=a[i] mod 2; a[i]:=a[i] div 2; end; c[j]:=x; while (a[t]=0) and (t>0) do dec(t); end; for i:=j downto 1 do write(c[i]); end; 4455666565565.65656565 begin readln(st); len:=length(st); p:=pos('.',st); st1:=copy(st,1,p-1); st2:=copy(st,p+1,len-p); len1:=length(st1); len2:=length(st2); for i:=1 to 1000 do begin a[i]:=0 ;b[i] :=0;c[i]:=0; end; for i:=1 to len1 do a[i]:=ord(st1[len1-i+1])-48; for i:=1 to len2 do b[i]:=ord(st2[len2-i+1])-48; changez(len1); write('.'); changex(len2); end.

  5. procedure changez(t:integer); var i,j,x:integer; begin j:=0; while t<>0 do begin inc(j); x:=0; for i:= t downto 1 do begin a[i]:=x*10+a[i]; x:=a[i] mod 2; a[i]:=a[i] div 2; end; c[j]:=x; while (a[t]=0) and (t>0) do dec(t); end; for i:=j downto 1 do write(c[i]); end; 2 1 5 3 1 8 6 7 0 7 6 5 9 8 3 1

  6. procedure changex(t:integer); var i,j,q,x:integer; begin for i:=1 to 5 do begin q:=0; for j:=1 to len2 do begin x:=b[j]*2+q; q:=x div 10; b[j]:=x mod 10; end; write(q); end; end; 6 5 6 5 6 5 6 5 2 ×

  7. 进制转换K进制 function dectok(x,k:longint):string; const alph='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; var st:string; begin st:=''; while x<>0 do begin st:=alph[x mod k+1]+st; x:=x div k; end; exit(st); end;

  8. K进制转换十进制 function ktodec(st:string; k:longint):longint; const alph='012456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; var i,j,ans:longint; begin ans:=0; j:=1; for i:=length(st) downto 1 do begin inc(ans,j*(pos(st[i],alph)-1)); j:=j*k; end; exit(ans); end;

  9. 题1128:基础二进制小数 题1258:【基础】任意进制转换

More Related