欢迎来到天天文库
浏览记录
ID:51588792
大小:94.50 KB
页数:19页
时间:2020-03-24
《程序阅读 - 龙岗教育信息网.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、程序阅读程序阅读题的特点不会告诉你程序的功能按要求直接写出程序的运行结果。运行结果通过write或writeln语句输出。多数情况下需要选手揣摩题目中包括的算法,而有些算法在教科书中找不到.程序阅读题的两种分析法模拟法:手工模拟程序的运行,当程序不太复杂时,它是一种有效的方法,理论上可以得出任何程序的运行结果。具体分析时,必须跟踪程序运行时各变量的变化。“有意义”分析法:找到某一程序段所实现的功能,简化分析。这是一种高效的方法,但不容易找到规律。举几个例子说明programPrograml;vara,x,y,okl,ok
2、2:integer;begina:=100:x:=l0;y:=20;okl:=5:ok2:=0;if((x>y)or((y<>20)and(okl=0))and(ok2<>0))thena:=1elseif((okl<>0)and(ok2=0))thena:=-1elsea:=0;writeln(a);end.输出:Answer-1vara,b:integer;beginread(a);b:=(a*(a*a))+1;ifbmod3=0thenb:=bdiv3;ifbmod5=0thenb:=bdiv5;ifbmod7=0
3、thenb:=bdiv7;ifbmod9=0thenb:=bdiv9;ifbmod11=0thenb:=bdiv11;ifbmod13=0thenb:=bdiv13;ifbmod15=0thenb:=bdiv15;writeln((100*a-b)div2);end.输入:10输出:Answer499programProgram2;vara,t:string;i,j:integer;begina:=‘morning’;j:=1;fori:=2to7doif(a[j]4、1tojdowrite(a[i]);end.输出:AnswermoProgramex301;varu:array[0..3]ofinteger;i,a,b,x,y:integer;beginy:=10;fori:=0to3doread(u[i]);a:=(u[0]+u[1]+u[2]+u[3])div7;b:=u[0]div((u[1]-u[2])divu[3]);x:=(u[0]+a+2)-u[(u[3]+3)mod4];if(x>10)theny:=y+(b*100-u[3])div(u[u[0]mod3]*5)el5、sey:=y+20+(b*100-u[3])div(u[u[0]mod3]*5);writeln(x,',',y);end.{*注:本例中,给定的输入数据可以避免分母为0或下标越界。}输入:9394输出:_______________Answer10,10Programex303;constNN=7;typeArr1=array[0..30]ofchar;vars:arr1;k,p:integer;functionfun(s:arr1;a:char;n:integer):integer;varj:integer;begi6、nj:=n;while(a0)dodec(j);fun:=j;end;beginfork:=1toNNdos[k]:=chr(ord('A')+2*k+1);k:=fun(s,'M',NN);writeln(k);end.输出:_____________Answer5Programex302;constm:array[0..4]ofinteger=(2,3,5,7,13);vari,j:integer;t:longint;beginfori:=0to4dobegint:=1;forj:=1tom[7、i]-1dot:=t*2;t:=(t*2-1)*t;write(t,'');end;writeln;end.输出:____________________Answer628496812833550336prgoramchu7_4;varn,k,i:integer;a:array[1..40]ofinteger;procedurefind(x:integer);vars,i1,j1:integer;p:boolean;begini1:=0;p:=true;whilepdobegini1:=i1+1;s:=0;forj1:=8、1tondoifa[j1]>a[i1]thens:=s+1;if(s=x-1)thenbeginwriteln(a[i1]);p:=falseend;endend;beginreadln(n,k);fori:=1tondoread(a[i]);find(k);find(n-k);end.输入:104123456567
4、1tojdowrite(a[i]);end.输出:AnswermoProgramex301;varu:array[0..3]ofinteger;i,a,b,x,y:integer;beginy:=10;fori:=0to3doread(u[i]);a:=(u[0]+u[1]+u[2]+u[3])div7;b:=u[0]div((u[1]-u[2])divu[3]);x:=(u[0]+a+2)-u[(u[3]+3)mod4];if(x>10)theny:=y+(b*100-u[3])div(u[u[0]mod3]*5)el
5、sey:=y+20+(b*100-u[3])div(u[u[0]mod3]*5);writeln(x,',',y);end.{*注:本例中,给定的输入数据可以避免分母为0或下标越界。}输入:9394输出:_______________Answer10,10Programex303;constNN=7;typeArr1=array[0..30]ofchar;vars:arr1;k,p:integer;functionfun(s:arr1;a:char;n:integer):integer;varj:integer;begi
6、nj:=n;while(a0)dodec(j);fun:=j;end;beginfork:=1toNNdos[k]:=chr(ord('A')+2*k+1);k:=fun(s,'M',NN);writeln(k);end.输出:_____________Answer5Programex302;constm:array[0..4]ofinteger=(2,3,5,7,13);vari,j:integer;t:longint;beginfori:=0to4dobegint:=1;forj:=1tom[
7、i]-1dot:=t*2;t:=(t*2-1)*t;write(t,'');end;writeln;end.输出:____________________Answer628496812833550336prgoramchu7_4;varn,k,i:integer;a:array[1..40]ofinteger;procedurefind(x:integer);vars,i1,j1:integer;p:boolean;begini1:=0;p:=true;whilepdobegini1:=i1+1;s:=0;forj1:=
8、1tondoifa[j1]>a[i1]thens:=s+1;if(s=x-1)thenbeginwriteln(a[i1]);p:=falseend;endend;beginreadln(n,k);fori:=1tondoread(a[i]);find(k);find(n-k);end.输入:104123456567
此文档下载收益归作者所有