题型:综合题 题类:常考题 难易度:困难
浙江省“温州十五校联合体”2018-2019学年高二下学期信息技术期中考试试卷
原始数据:
a(1) |
a(2) |
a(3) |
a(4) |
1 |
2 |
3 |
4 |
方法一:
①向右旋转1步:
a(1) |
a(2) |
a(3) |
a(4) |
4 |
1 |
2 |
3 |
②向右旋转2步:
a(1) |
a(2) |
a(3) |
a(4) |
3 |
4 |
1 |
2 |
③向右旋转3步:
a(1) |
a(2) |
a(3) |
a(4) |
2 |
3 |
4 |
1 |
方法二:
①将a(1)值放至旋转3个位置后位置a(4):
a(1) |
a(2) |
a(3) |
a(4) |
1 |
2 |
3 |
1 |
②将原a(4)值放至旋转3个位置后位置a(3):
a(1) |
a(2) |
a(3) |
a(4) |
1 |
2 |
4 |
1 |
③将原a(3)值放至旋转3个位置后位置a(2):
a(1) |
a(2) |
a(3) |
a(4) |
1 |
3 |
4 |
1 |
④将原a(2)值放至旋转3个位置后位置a(1):
a(1) |
a(2) |
a(3) |
a(4) |
2 |
3 |
4 |
1 |
有n个数存储在数组a中,给定一个整数p(1≤p≤n),将数组a的前p个数与后n-p个数分别向右旋转k次。例如数组a的各个数值分别是1,2,3,4,5,6,7,当p=4,k=1时,旋转后的结果为4,1,2,3,7,5,6。小明为此编写了VB程序,功能如下:在文本框Text2、Text3中依次输入p和k的值,单击“旋转数组”按钮Command1后,数组旋转后结果显示在Text4中。程序运行界面如图1所示,请回答下列问题:
图1
Dim a(20) As Integer
Const n = 20
Private Sub Form_Load()
'随机产生n个[1,100]之间的随机整数,依次存储到a(1)、a(2)、…a(n)中,并在文本框Text1显示,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, p As Integer, k As Integer,cnt As Integer,c As Integer,t As Integer
p = Val(Text2.Text)
k = Val(Text3.Text)
i = 1:start = 1:c = a(i):cnt = 1
Do While cnt<= p '方法二
i =
t = a(i)
a(i) = c
If Then
start = start + 1
i = i + 1
c = a(i)
Else
c = t
End If
cnt = cnt + 1
Loop
For i = 1 To k '方法一
temp = a(n)
For j =
a(j) = a(j - 1)
Next j
a(p + 1) = temp
Next i
For i = 1 To n
s = s + Str(a(i))
Next i
Text4.Text = s
End Sub
排序前 |
71 |
85 |
64 |
55 |
42 |
62 |
33 |
17 |
34 |
30 |
排序后 |
71 |
85 |
17 |
55 |
33 |
30 |
62 |
42 |
34 |
64 |
实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n=10
Dim a(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer,j As Integer
Dim temp As Integer,flag As Boolean
'读取一组正整数,存储在数组a中,代码略
i=1:j=n
temp=a(j):flag=True
Do While i<j
If flag Then
If a(i) Mod 2=0 Then
a(j)=a(i)
j=j-1
flag=Not flag
Else
'{#blank#}1{#/blank#}
End If
Else
If a(j) Mod 2=1 Then
a(i)=a(j)
flag=Not flag
Else
j=j-1
End If
End If
Loop
' {#blank#}2{#/blank#}
'依次输出排序后的数据,代码略。
End Sub
图 a | 图 b |
t=h
p=d[h][1]
while p != -1 :
q=d[p][1]
p=q
d[t][-1]=-1
试题篮