if (a1[i]=0) then begin
write(i:4); inc(t);
if (t mod 10=0) then writeln; end; writeln; end.
输出:_____________________________________________ _____________________________________________
4、Program j304; Type str1=string[100]; Str2=string[200]; Var
S1:str1; s2:str2;
Function isalpha(c:char):Boolean; Var i:integer; Begin i:=ord(c);
if ((i>=65) and (i<=90)) or ((i>=97) and (i<=122)) then isalpha:=true
else isalpha:=false; end;
function isdigit(c:char):Boolean; var i:integer; begin
i:=ord(c); if (i>=48) and (i<=57) then isdigit:=true else isdigit:=false; end;
procedure expand(s1:str1;var s2:str2); var i,j:integer; a,b,c:char; begin
j:=1; c:=char(1); i:=0; while (i<=ord(s1[0])) do begin inc(i); c:=s1[i]; if c='-' then begin {1} a:=s1[i-1]; b:=s1[i+1];
if (isalpha(a) and isalpha(b)) or (isdigit(a) and isdigit(b)) then begin dec(j);
while (ord(upcase(a)) s2[j]:=a; inc(j); inc(a); end; end else begin s2[j]:=c; inc(j); end; end{1} else begin s2[j]:=c; inc(j); end; end; s2[0]:=char(j-2); end; begin readln(s1); expand(s1,s2); writeln(s2); end. 输入:wer2345d-h454-82qqq 输出:__________________________ 四、完善程序(前4空,每空2.5分,后6空,每空3分,共28分)。 1、(求字符的逆序)下面的程序的功能是输入若干行字符串,每输入一行,就按逆序输出该行,最后键入-1终止程序。 请将程序补充完整。 Program j401; type str1=string[100]; var line:str1; kz:integer; procedure reverse(var s:str1); var I,j:integer; t:char; begin i:=1; j:=length(s); while (i __________;____________ ; end; end; begin writeln(‘continue? -1 for end.’); readln(kz); while ( ___________)do begin readln(line); __________; writeln(line); writeln(‘continue? -1 for end.’); readln(kz); end; end. 2 2 3 3 2 -1 1 3 4 1 1 5 4 4 5 5 2、(棋盘覆盖问题)在一个2k×2 k个方格组成的棋盘中恰有一个方格与其它方格不同(图中标记为-1的方格),称之为特殊方格。现用L型(占3个小方格)纸片覆盖棋盘上除特殊方格的所有部分,各纸片不得重叠,于是,用到的纸片数恰好是(4 k-1)/3。在下表给出的一个覆盖方案中,k=2,相同的3各数字构成一个纸片。 下面给出的程序使用分治法设计的,将棋盘一分为四,依次处理左上角、右上角、左下角、右下角,递归进行。请将程序补充完整。 Program j402; type arr1=array[1..65] of integer; arr2=array[1..65] of arr1; var board:arr2; tile:integer; size,dr,dc:integer; procedure chessboard(tr,tc:integer; dr,dc:integer; var size:integer); var t,s:integer; begin if (size=1) then ____________; t:=tile; inc(tile); s:=size div 2; if then chessboard(tr,tc,dr,dc,s) else begin board[tr+s-1]:=t; ______________; end; if (dr=tc+s) then chessboard(tr,tc+s,dr,dc,s) else begin board[tr+s-1][tc+s]:=t; ______________; end; if (dr>=tr+s) and (dc if (dr>=tr+s) and (dc>=tc+s) then chessboard(tr+s,tc+s,dr,dc,s) else begin board[tr+s][tc+s]:=t; ______________; end; end; procedure prt1(n:integer); var I,j:integer; begin for I:=1 to n do begin for j:=1 to n do write(board[i][j]:3); writeln; end; end; begin writeln(‘input size(4/8/16/64):’); readln(size); writeln(‘input the position of special block(x,y):’); readln(dr,dc); board[dr][dc]:=-1; tile:=1; chessboard(1,1,dr,dc,size); prt1(size); end. NOIP2007年提高组(Pascal语言)参考答案与评分标准 一、单项选择题:(每题1.5分) 1. D 2. E 3. D 4. B 5. A 6. B 7. D 8. B 9. D 10. A 二、 不定项选择题(共10题,每题1.5分,共计15分。每题正确答案的个数大于或等于1。多选或少选均不得分)。 11. ABC 12. AD 13. ABD 14. ABD 15. BC 16. ABD 17. AB 18. CD 19. BC 20. AC 三、问题求解:(共2题,每题5分,共计10分) 1.350 2.289 四、阅读程序写结果(共4题,每题8分,共计32分) 1 129,43 2 No.1:3,6 No.2:3,6 3 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 4 No.1: XTORSEAAMPLE No.2: AAEELMOPRSTX 五.完善程序 (前5空,每空2分,后6空,每空3分,共28分) (说明:以下各程序填空可能还有一些等价的写法,各省可请本省专家审定和上机验证,不一定上报科学委员会审查) 1 ① bound*2 ② exit ③ j:=0 ④ (j mod b-(b div 2))=0 ⑤ downto 1 2 ① x[i-2]*(m-1) ② j+x[i-1]*k ③ j+x[i-1]*k ④ r-1 ⑤ x[i-1]+1 ⑥ backtrace(i+1,r)