NOIP阅读读程序写结果模拟题_第1页
NOIP阅读读程序写结果模拟题_第2页
NOIP阅读读程序写结果模拟题_第3页
NOIP阅读读程序写结果模拟题_第4页
NOIP阅读读程序写结果模拟题_第5页
免费预览已结束,剩余29页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、程序PROGRAM EX1;VAR n,i,j,k:integer;BEGIN write(Enter n : ); readln(n); for i:=1 to n do begin for j:=1 to n do begin if i=j then k:=j else k:=i; write(k:4) end; writeln endEND.Enter n : 7输出:1 1 1 1 1 1 11 2 2 2 2 2 21 2 3 3 3 3 31 2 3 4 4 4 41 2 3 4 5 5 51 2 3 4 5 6 61 2 3 4 5 6 72、程序PROGRAM EX2;VAR n,i,j,k,mi,ma:integer;BEGIN write(Enter n :); readln(n); for i:=1 to n do begin if i=n+1-i then ma:=i else ma:=n+1-i; mi:=n+1-ma; k:=1; for j:=1 to n do begin write(k:4); if j=ma then k:=k-1; end; writeln endEND.Enter n : 7输出:1 1 1 1 1 1 11 2 2 2 2 2 11 2 3 3 3 2 11 2 3 4 3 2 11 2 3 3 3 2 11 2 2 2 2 2 11 1 1 1 1 1 13、程序PROGRAM EX3;VAR n,i,j,r,c,k,m:integer;BEGIN write(Enter n : ); readln(n); for i:=1 to n do begin for j:=1 to n do begin if i+j=n+1 then k:=(i+j-2)*(i+j-1) div 2+i else begin r:=n+1-i; c:=n+1-j; k:=n*n+1-(r+c-2)*(r+c-1) div 2-r end; write(k:4) end; writeln endEND.Enter n : 7输出:1 2 4 7 11 16 223 5 8 12 17 23 296 9 13 18 24 30 3510 14 19 25 31 36 4015 20 26 32 37 41 4421 27 33 38 42 45 4728 34 39 43 46 48 494、程序PROGRAM EX4;VAR a:array1.20,1.20of integer; n,i,j,r,c,k:integer;BEGIN write(Enter n : ); readln(n); for i:=1 to n do begin for j:=1 to n do begin if i+jj then k:=i*i+1-j else k:=j*j+1+i-j-j; write(k:3) end; writeln endEND.Enter n : 8输出: 1 2 5 10 17 26 37 50 4 3 6 11 18 27 38 51 9 8 7 12 19 28 39 52 16 15 14 13 20 29 40 53 25 24 23 22 21 30 41 54 36 35 34 33 32 31 42 55 49 48 47 46 45 44 43 56 64 63 62 61 60 59 58 576、程序PROGRAM EX6;VAR n,i,j,k,r,c,ma:integer;BEGIN write(Enter n : ); readln(n); for r:=1 to n do begin for c:=1 to n do begin i:=r;j:=c; if rc then ma:=r else ma:=c; if ma mod 2=1 then begin i:=c;j:=r end; if ij then k:=i*i+1-j else k:=j*j+1+i-j-j; write(k:3) end; writeln endEND.Enter n : 8输出:1 2 9 10 25 26 49 50 4 3 8 11 24 27 48 51 5 6 7 12 23 28 47 52 16 15 14 13 22 29 46 53 17 18 19 20 21 30 45 54 36 35 34 33 32 31 44 55 37 38 39 40 41 42 43 56 64 63 62 61 60 59 58 577、程序PROGRAM EX7;VAR q,r:array0.100of integer; m,n,i,j,k:integer;BEGIN for i:=0 to 100 do qi:=-1; write(m,n : ); readln(m,n); write(m,/,n, = ,m div n,.); k:=m mod n; i:=0; while qk=-1 do begin qk:=i; ri:=k*10 div n; k:=k*10 mod n; i:=i+1; end; for j:=0 to qk-1 do write(rj); if k0 then begin write(char(39); for j:=qk to i-1 do write(rj); write(char(39); end; writelnEND.输入:m,n : 123 15m,n : 3 7m,n : 100 12m,n : 1000 71分别输出:123/15 = 8.23/7 = 0.428571100/12 = 8.31000/71 = 14.084507042253521126760563380281690148、程序PROGRAM EX8;CONST x=3;VAR y,m,d,day:integer; mn:array0.6of string8;BEGINmn0:=Sunday;mn1:=Monday; mn2:=Tuesday;mn3:=Wensday;mn4:=Thursday;mn5:=Friday; mn6:=Saturday; write(year,month,day : ); readln(y,m,d);write(y:4,.,m,.,d, is );if m3 then begin m:=m+12; y:=y-1 end; day:=(y+(y div 4)-(y div 100)+(y div 400) +(m-3)*2+(m*3-7)div 5+d-1+x)mod 7; writeln(mnday,.)END.输入: year,month,day : 2002 5 30输出:2002.5.30 is Thursday.9、程序PROGRAM EX9;CONST n=20;VAR i,j,q:integer;BEGIN i:=3; while in do begin q:=trunc(sqrt(i); j:=3; while (j=q) and (i mod j0) do j:=j+2; if jq then write(i:8); i:=i+2 end; writelnEND.输出:2 3 5 7 11 13 17 1910、程序PROGRAM EX10;CONST n=25;VAR i,j,d,k,m:integer; p,q:array1.30of integer; pr:boolean;BEGIN k:=1;m:=1;p1:=5;q1:=25;i:=7;d:=4; while i=qj then begin pr:=pr and (i qj); qj:=qj+2*pj end; if i=qk then begin pr:=false; qk:=qk+2*pk; k:=k+1 end; if pr thenbegin write(i:8); if qmm THEN tmp:=part(m,m) ELSE BEGIN st.push(n); tmp:=part(m-n,n-1); st.pop; tmp:=tmp+part(m,n-1); END; part:=tmp; END; BEGIN st.creat; write(Enter m & n : ); readln(m,n); s:=part(m,n); writeln(INPART(,m,n,)=,s);END.Enter m & n : 7 8输出:INPART(7,8)=1512、程序PROGRAM ex12; USES stackun; VAR s,n:integer; w:array1.20of integer; ch:char; ok:boolean; st:stack; FUNCTION knap(s,n:integer):boolean; VAR tmp:boolean; BEGINIF (s=0)AND(n=0) THEN BEGIN knap:=true;st.print END ELSE IF s0 THEN knap:=false ELSE BEGIN st.push(wn); tmp:=knap(s-wn,n-1); st.pop; knap:=tmp OR knap(s,n-1); END END;BEGIN st.creat; n:=0;ch:= ; write(knapsack = );readln(s); write(Enter some weights : );while chchr(26) DO begin n:=n+1;read(wn,ch) end; ok:=knap(s,n);END.knapsack = 7Enter some weights : 9 6 2Z输出:ok=FALSE!knapsack = 10Enter some weights : 1 6 2 7 5 7 2 1Z输出:ok=TRUE!13、程序PROGRAM ex13;VAR a:array1.8of integer; b,c,d:ARRAY-7.16of boolean; m,i:integer;PROCEDURE try(n:integer);VAR j:integer;BEGIN IF n=9 THEN BEGIN m:=m+1; write(,m:2,) ); FOR j:=1 TO 8 DO write(aj:2); writeln END ELSE FOR j:=1 TO 8 DO IF bj AND cn+j AND dn-j THEN BEGIN an:=j; bj:=false; cn+j:=false; dn-j:=false; try(n+1); bj:=true; cn+j:=true; dn-j:=true ENDEND;BEGIN FOR i:=-7 TO 16 DO BEGIN bi:=true; ci:=true; di:=true END; m:=0; try(1)END.请写出以425打头的一组数:答:4 2 5 8 6 1 3 714、程序PROGRAM ex14; VAR m,n,s:integer; FUNCTION cmn(m,n:integer):integer; VAR a:ARRAY0.20of RECORD m,n:integer END; i,k,tmp:integer; BEGIN tmp:=0;k:=1;ak.m:=m;ak.n:=n; WHILE k0 DO IF ak.n=0 THEN BEGIN tmp:=tmp+1; FOR i:=1 TO k-1 DO write(ai.m:3); writeln; k:=k-1; ak.m:=ak.m-1 END ELSE IF ak.mn)or(m0) THEN tmp:=0 ELSE BEGIN st.push(1);tmp:=stackop(m-1,n);st.pop; st.push(0);tmp:=tmp+stackop(m,n-1);st.pop; END; stackop:=tmp; END;BEGIN st.creat; write(Enter n : ); readln(n); s:=stackop(n,n); writeln(stack(,n,)=,s);END.Enter n : 4输出:stack(4)=1416、程序PROGRAM EX16;VAR n,m:integer;FUNCTION f(n:integer):integer; VAR tmp,i:integer; BEGIN tmp:=1; FOR i:=1 TO (n DIV 2) DO tmp:=tmp+f(i); f:=tmp; END;BEGIN write(n = );readln(n); m:=f(n); writeln(f(,n,)=,m)END.输入:n = 6输出:f(6)=617、程序PROGRAM EX17;VAR x0,y0,p,m,n:longint;FUNCTION cpr(m,n:longint):boolean; VAR tmp:longint; BEGIN tmp:=n; WHILE m MOD n0 DO BEGIN tmp:=m MOD n; m:=n; n:=tmp END; cpr:=tmp=1; END;BEGIN write(x0(2.1000) & y0(2.1000 = );readln(x0,y0); m:=y0 div x0;n:=0; FOR p:=1 TO m DO IF(m MOD p=0)AND cpr(p,m DIV p) THEN BEGIN n:=n+1; writeln(p*x0:8,y0 DIV p:8) END; writeln(f(,x0,y0,)=,n)END.输入:x0(2.1000) & y0(2.1000) = 3 60输出: 3 60 12 15 15 12 60 3f(3,60)=418、程序PROGRAM EX18;VAR I,J:INTEGER;A,X,Y,Z:STRING;BEGIN A:=BAABCDDCAB; I:=6; WHILE I=2 DO BEGIN X:=; FOR J:=I TO I*I-1 DO X:=X+AI; Y:=A; Y0:=CHR(I); Z:=; FOR J:=LENGTH(A)-I+1 TO LENGTH(A) DO Z:=Z+AJ; Z:=X+Y+Z; I:=I-2 END; WRITELN(Z)END.输出:19、程序PROGRAM EX19;VAR I,S,T,X:INTEGER;PROCEDURE PP(Y:INTEGER);BEGIN T:=1; FOR I:=1 TO X DO T:=T*I+1;END;BEGIN X:=5; S:=4; PP(X); S:=S+T; X:=3; PP(X); S:=S-T; X:=5; WRITELN(S=,S); WRITELN(X=,X)END.输出:20、程序Program EX20(input,output);const n=4;type se=array1.n*2 of char;var i,j,i1,j1,k,s,t,s1,L,swap:integer; temp :char; a :se;Begin for i:=1 to n*2 do read(ai); readln; s:=0; t:=0; for i:=1 to n*2 do if ai=1 then s:=s+1 else if ai=0 then t:=t+1; if (sn) or (tn) then writeln(error) else begin s1:=0; for i:=1 to 2*n-1 do if aiai+1 then s1:=s1+1; writeln(jamp=,s1); swap:=0; for i:=1 to 2*n-1 do for j:=i+1 to 2*n do if aiaj then begin temp:=ai;ai:=aj;aj:=temp; s:=0; for L:=1 to 2*n-1 do if aLaL+1 then s:=s+1; if sswap then begin swap:=s; i1:=i; j1:=j end; temp:=ai;ai:=aj;aj:=temp end; if swap0 then writeln(maxswap=,swap-s1, i=,i1, j=,j1) end End.输入:10101100输出:21、程序Program ex21(input,output);VAR I,J,S:INTEGER; B :ARRAY0.5 OF INTEGER;BEGIN S:=1; FOR I:=1 TO 5 DO BI:=I; J:=1; WHILE J0 DO BEGIN J:=5; WHILE (J0) AND (BJ=10+J-5) DO J:=J-1; IF J0 THEN BEGIN S:=S+1; BJ:=BJ+1; FOR i:=J+1 TO 5 DO Bi:=BJ+i-J END; END; WRITELN(S=,S);END.输出:22、程序program ex22(input,output);VAR i, s, max:integer; a:array1.10 of integer;Begin for i:=1 to 10 do read(ai); max:=a1; s:=a1; for i:=2 to 10 do begin if smax then max:=s end; writeln(max=,MAX)End.输入:8 9 1 24 6 5 11 15 28 9输出:max=23、程序PROGRAM EX23;var i,x,x1,x2:integer;begin x1:=3; x2:=8; for i:=1 to 5 do begin x:=(x1+x2)*2; x1:=x2; x2:=x end; writeln(x=,x)end.输出:24、程序PROGRAM EX24;const maxn=20;var i,j,k,n:integer;a:array 1.maxn,1.maxn of integer;begin write(Input n=); readln(n); i:=1; j:=(n+1) div 2; for k:=1 to n*n do begin ai,j:=k; if k mod n=0 then i:=i+1else begin i:=i-1;j:=j+2 end; if in then i:=i-n; if in then j:=j-n end; for i:=1 to n do begin for j:=1 to n do write(ai,j:3); writeln endend.写出n=5时的运行结果。25、程序PROGRAM EX25;var i,k:integer;a:array 0.20 of integer;begin a1:=1; a2:=1; k:=1; repeat ak+2:=1; for i:=k+1 downto 2 do ai:=ai+ai-1; k:=k+1; until k=10; for i:=1 to 11 do write(ai:5); writelnend.输出:26、程序PROGRAM EX26;var m,n:integer;function ack(m,n:longint):longint;begin if m=0 then ack:=n+1 else if n=0 then ack:=ack(m-1,1) else ack:=ack(m-1,ack(m,n-1)end;begin write(Input m,n=); readln(m,n); writeln(ack(,m,n,)=,ack(m,n)end.分别写出m=1,n=3; m=2,n=4; m=3,n=3 m=3,n=4时的运行结果。27、程序PROGRAM EX27;const n=20;var i,j,k,l:integer;a:array0.n of integer;begin write(Input k=); readln(k); j:=1; while k=j do begin aj:=j; k:=k-j; j:=j+1 end; l:=j-1; while k0 do begin al:=al+1; k:=k-1; l:=l-1 end; for i:=1 to j-1 do write(ai:4); writelnend.输入:11输出:28、程序PROGRAM EX28;var i,n:longint;begin write(Input n=); readln(n); i:=2; while n1 do begin while n mod i=0 do begin write(i, ); n:=n div i end; i:=i+1 end; writelnend.写出n=27720时的运行结果。29、程序PROGRAM EX29;function s(n:integer):integer;begin if n=0 then s:=0 else s:=s(n-1)+nend;begin writeln(s(100)end.输出:30、程序PROGRAM EX30;const maxn=10;var i,j,n:integer;a:array -maxn.maxn,-maxn.maxn of integer;begin n:=9; for i:=-n to n do begin for j:=-n to n do begin if abs(i)0 then begin turn(n div 8); write(n mod 8) endend;begin n:=32766; turn(n)end.输出:32、程序PROGRAM EX32;var x,y:longint;begin x:=270270; y:=20691; while (x0) and (y0) do begin if x=y then x:=x-y else y:=y-x end; if x=0 then writeln(y) else writeln(x)end.输出:33、程序PROGRAM EX33;Var i,j,n:integer;a:array1.1000 of integer;begin n:=200; for i:=1 to n do ai:=0; for i:=1 to n do begin j:=i; while j=n do begin aj:=1-aj; j:=j+i end end;for i:=1 to n do if ai=1 then write(i:5)end.输出:34、程序PROGRAM EX34;var i,j,k,p,q,r:integer;a,b:array1.1000 of integer;function check(k:integer):boolean;var i:integer; temp:boolean;begin temp:=true; for i:=1 to k-1 do if bi=bk then temp:=false; check:=tempend;begin p:=23; q:=79; r:=p; k:=0; repeat r:=10*r; k:=k+1; ak:=r div q; bk:=r mod q; r:=bk until (r=0) or not(check(k); if r=0 then for i:=1 to k do write(ai) else begin j:=1; while bjr do j:=j+1; for i:=1 to j do write(ai); write(); for i:=j+1 to k do write(ai); write() end; writelnend.输出:35、程序PROGRAM EX35;const maxn=8;type arraytype=array 1.maxn of integer;var i,n:integer;a:arraytype;procedure p(k:integer;a:arraytype);var i,temp:integer; b:arraytype;begin if k=n then begin for i:=1 to n do write(ai, ); writeln end else for i:=k to n do begin b:=a; temp:=bk; bk:=bi; bi:=temp; p(k+1,b) endend;begin n:=4; for i:=1 to n do ai:=i; p(1,a);end.输出:36、程序PROGRAM EX36;const maxn=8;type arraytype=array 0.maxn of integer;var i,j,k,n:integer;a,b,c:arraytype;begin n:=4; for i:=0 to n do ai:=0; repeat for i:=0 to n do ci:=i+1; for i:=n-1 downto 0 do begin bi:=cai; for j:=ai to n-1 do cj:=cj+1 end; for i:=n-1 downto 0 do write(bi, ); writeln; a0:=a0+1; i:=0; while aii do begin ai+1:=ai+1+1; ai:=0; i:=i+1 end; until an0end.37、程序PROGRAM EX37;var i,j,k,n,r:integer;a:array0.100 of integer;begin n:=6; r:=3; for i:=0 to r do ai:=i; while a0=0 do begin for i:=1 to

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论