Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
程序阅读 PowerPoint Presentation
Download Presentation
程序阅读

程序阅读

111 Views Download Presentation
Download Presentation

程序阅读

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. 程序阅读

  2. 程序阅读题的特点 • 不会告诉你程序的功能 • 按要求直接写出程序的运行结果。运行结果通过write或writeln语句输出。 • 多数情况下需要选手揣摩题目中包括的算法,而有些算法在教科书中找不到.

  3. 程序阅读题的两种分析法 • 模拟法:手工模拟程序的运行,当程序不太复杂时,它是一种有效的方法,理论上可以得出任何程序的运行结果。 具体分析时,必须跟踪程序运行时各变量的变化。 • “有意义”分析法:找到某一程序段所实现的功能,简化分析。这是一种高效的方法,但不容易找到规律。

  4. 举几个例子说明 program Programl; var a,x,y,okl,ok2:integer; begin a :=100: x:=l0; y:=20; okl:=5: ok2:=0; if ((x>y) or ((y<>20) and (okl=0)) and (ok2<>0)) then a:=1 else if ((okl<>0) and (ok2=0)) then a:=-1 else a:=0; writeln(a); end. 输出:    

  5. Answer -1

  6. var a, b : integer; begin read(a); b := (a * (a * a)) + 1; if b mod 3 = 0 then b := b div 3; if b mod 5 = 0 then b := b div 5; if b mod 7 = 0 then b := b div 7; if b mod 9 = 0 then b := b div 9; if b mod 11 = 0 then b := b div 11; if b mod 13 = 0 then b := b div 13; if b mod 15 = 0 then b := b div 15; writeln((100 * a - b) div 2); end. 输入:10 输出:

  7. Answer 499

  8. program Program2; var a,t:string; i,j:integer; begin a:=‘morning’; j:= 1; for i:=2 to 7 do if (a[j]<a[i])then j:= i; j:= j-1; for i:=1 to j do write (a[i]); end. 输出:

  9. Answer mo

  10. Program ex301; var u:array[0..3] of integer; i,a,b,x,y:integer; begin y:=10; for i:=0 to 3 do read(u[i]); a:=(u[0]+u[1]+u[2]+u[3]) div 7; b:=u[0] div ((u[1]-u[2]) div u[3]); x:=(u[0]+a+2)-u[(u[3]+3) mod 4]; if (x>10) then y:=y+(b*100-u[3]) div (u[u[0] mod 3]*5) else y:=y+20+(b*100-u[3]) div (u[u[0] mod 3]*5); writeln (x,',',y); end. {*注:本例中,给定的输入数据可以避免分母为0或下标越界。 } 输入:9 3 9 4 输出:_______________

  11. Answer 10,10

  12. Program ex303; const NN=7; type Arr1=array[0..30] of char; var s:arr1; k,p:integer; function fun(s:arr1; a:char;n:integer):integer; var j:integer; begin j:=n; while (a<s[j])and(j>0) do dec(j); fun:=j; end; begin for k:=1 to NN do s[k]:=chr(ord('A')+2*k+1); k:=fun(s,'M',NN); writeln(k); end. 输出:_____________

  13. Answer 5

  14. Program ex302; const m:array[0..4] of integer=(2,3,5,7,13); var i,j:integer; t: longint; begin for i:=0 to 4 do begin t:=1; for j:=1 to m[i]-1 do t:=t*2; t:=(t*2-1)*t; write (t,' '); end; writeln; end. 输出:____________________

  15. Answer 6 28 496 8128 33550336

  16. prgoram chu7_4;var n,k,i:integer;a:array[1..40]of integer;procedure find(x:integer);var s,i1,j1:integer;p:boolean;begini1:=0;p:=true;while p dobegini1:=i1+1;s:=0;for j1:=1 to n do if a[j1]>a[i1]then s:=s+1;if(s=x-1)thenbeginwriteln(a[i1]);p:=falseend;endend;beginreadln(n,k);for i:=1 to n do read(a[i]);find(k);find(n-k);end.输入:10 412 34 5 65 67 87 7 90 120 13输出:

  17. Answer 67 34

  18. program ex304; var x,x2:longint; procedure digit(n,m:longint); var n2:integer; begin if(m>0) then begin n2:=n mod 10; write(n2:2); if(m>1) then digit(n div 10,m div 10); n2:=n mod 10; write(n2:2); end; end; begin writeln('Input a number:'); readln(x); x2:=1; While(x2<x) do x2:=x2*10; x2:=x2 div 10; digit(x,x2); writeln; end. 输入:9734526

  19. Answer 6 2 5 4 3 7 9 9 7 3 4 5 2 6(数字之间无空格扣2分)