阅读以下说明及Visual Basic程序代码,将应填入(n)上处的字句写在对应栏内。
[说明]
字符组合:程序界面如图示,在文本框Text1中输入若干个任意字符,单击“颠倒”按钮,将这些字符按相反的顺序显示在标签Lable1 中,并在标签Labs1 2处显示字符的个数。例如:输入abcabc2,显示为 2cbabca,组成字符数为4。
[Visual Basic 代码]
Private Sub cmdshow_ Click (
Dim n As Integer
Dim I As Integer
Dim str1 As String
N=Len (Text1.Text )
For I=n To Step- 1
Str1=(1)
Next I
Labe11. Caption=Str1
End Sub
Private Sub cmdcount_ Click ()
Dim n As Integer
Dim in As Integer
Dim i As Integer
Dim j As Integer
Dim flag As Integer
Dim str1 As Integer
Dim str2 As Integer
N=(2)
Str1 =Mid$ (Text1.Text, i. 1
For I =2 To n
Str2=mid$ (Text1,Text,I,1
M=Len (str1)
(3)
For j=1 To m
If (4) Then flag= 1; Exit For
Next j
If flag<>1 then str1=str1& str2
Next I
Lable2.Caption=(5)
End Sub
第1题
阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。
【说明】
函数diff的功能是:根据两个由整数(都大于-32768)按升序构成的单链表L1和L2(分别由A,B指向)构造一个单链表L3(由*r指向),要求13中的所有整数都是L1,并且不是 L2中的整数,还要求L3中的所有整数都两两不等。
【函数】
include < malloc. h >
typedef struct node {
int d;
struct node * next
} Node;
void diff(Node *A,Node * B,Node * * r)
{
int lastnum;
Node * p;
*r = NULL;
if( ! A) return;
while((1))
if(A->d < B ->d)
{
lastnum =A -> d;
p= ( Node * ) malloc( sizeof(Node) );
p->d = lastnum;
p->next= *r;(2);
do
A = A -> next;
while((3));
}
else if(A->d > B->d)
B=B- >next;
else {
(4);
lastnum=A -> d;
while ( A && A->d = = lastnum) A=A-> next;
}
while(A)
{
lastnum=A->d;
p=( Node * ) malloc( sizeof(Node) );
p-> d = lastnum;
(5);
*r=p;
while (A && A->d = = lastnum) A=A->next;
}
}
第2题
阅读以下说明和流程图,填补流程图中的空缺(1)~(5),将解答填入对应栏内。
【说明】
下面流程图的功能是:在已知字符串A中查找特定字符串B,如果存在,则输出B串首字符在A串中的位置,否则输出-1。设串A由n个字符A(0),A(1),…,A(n-1)组成,串B由m个字符B(0),B(1),…,B(m-1)组成,其中n≥m>0。在串A中查找串 B的基本算法如下:从串A的首字符A(0)开始,取子串A(0)A(1)…A(m-1)与串B比较;若不同,则再取子串A(1)A(2)…A(m)与串B比较,依次类推。
例如,字符串“CABBRFFD”中存在字符子串“BRF”(输出3),不存在字符子串“RFD”(输出-1)。
在流程图中,i用于访问串A中的字符(i=0,1,…,n-1),j用于访问串B中的字符(j=0,1,…,m-1)。在比较A(i)A(i/1)…A(i+m-1)与B(0)B(1)…B(m-1)时,需要对 A(i)与B(0)、A(i+1)与B(1)、…、A(i+j)与B(j)等逐对字符进行比较。若发现不同,则需要取下一个子串进行比较,依此类推。
【流程图】
第4题
割时的标志字符。例如,若str的值为“66981636666257”,del的值为“6”,调用此函数后,将输出3个子字符串,分别为“981”、“3”和“257”。请将函数f_str中(6)~(8)空缺处的内容填写完整。
[函数]
void f_str(char *str,char del)
{ int i,j,len;
len = strlen(str);
i = 0;
while (i<len) {
while ( (6) )
i++; /* 忽略连续的标志字符 */
/* 寻找从srt[i]开始直到标志字符出现的一个子字符串 */
j = i+1;
while (str[j] !=del && str[j] !='\0')
j++;
(7)="\0"; /* 给找到的字符序列置字符串结束标志 */
printf (" %s\t", & str [i]);
(8);
}
}
第5题
阅读以下技术说明和流程图,根据要求回答问题1至问题3。
[说明]
图4-8的流程图所描述的算法功能是将给定的原字符串中的所有前部空白和尾部空白都删除,但保留非空字符。例如,原字符串“ FileName ”,处理变成“File Name”。图4-9、图4-10和图4-11分别详细描述了图4-8流程图中的处理框A、B、C。
假设原字符串中的各个字符依次存放在字符数组ch的各元素ch(1)、ch(2)、…、ch(n)中,字符常量 KB表示空白字符。
图4-8所示的流程图的处理过程是:先从头开始找出该字符串中的第一个非空白字符ch(i),再从串尾开始向前找出位于最末位的非空白字符ch(j),然后将ch(i)、……、ch(j)依次送入ch(1)、ch(2)、……中。如果字符串中没有字符或全是空白字符,则输出相应的说明。
在图4-8流程图中,strlen()是取字符串长度函数。
请将图4-9、图4-10和图4-11流程图中(1)~(4)空缺处的内容填写完整。
第8题
阅读以下说明和C++代码,将解答写入对应栏内。
【说明】
请编写一个函数int SeqSearch(int list[],int start,int n,int key),该函数从start开始,在大小为n的数组list中查找key值,返回最先找到的key值的位置,如果没有找到则返回-1。请修改程序中画线部分的错误并将不同情况下的输出结果补充完整。
【程序】
文件search.cpp的内容如下:
include <iostream. h >
int SeqSearch( int list[ ] ,int start,int n,int key)
{
for(int i=start;i<=n;i++) //(1)
{
if( list[i] = key)//(2)
{
return i;
}
}
return -1;
}
void main( )
{
int A[10]
int key,count=0,pos;
cout <<" Enter a list of 10 integers:";
for(pos=0;pos<10;pos++)
{
cin >>A; //(3)
}
cout <<" Enter a key; ";
cin >> key;
pos=0;
while(( pos = SeqSearch ( A, pos, 10, key)) !=-1 )
{
count ++;
pos ++;
}
cout<<key<<"occurs" <<count<< (count!=1?" times":" time") <<" in the list,"
<< endl;
}
第一种情况:输入2 3 12 6 8 45 8 33 7输入key:8
输出:(4)
第二种情况:输入2 3 126 8 45 8 33 7输入k6y:9
输出:(5)
第9题
阅读以下说明及Visual Basic 程序代码,将应填入(n)处的字句写在对应栏内。
[说明]
本程序求3~100之间的所有素数(质数)并统计个数;同时将这些素数从小到大依次写入顺序文件E: \dataout.txt;素数的个数显示在窗体Form1上。
[Visual Basic 代码]
Private Sub Command1_ Click ( )
Dim count as integer, flag as Boolean
Dim t1 as Integer, t2 as Integer
(1)
Count=0
For t1=3 to 100
Flag=Tree
For t2=2 to Int( Sqr ( t1 ) )
If (2) Then flag=False
Next t2
(3)
count=(4)
write 1, t1
End if
Next t1
(5)
Close 1
End Sub
第10题
阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。
【说明】
函数QuickSort是在一维数组A[n]上进行快速排序的递归算法。
【函数】
void QuickSort( int A[ ],int s,int t)
{ int i=s,j=t+1,temp;
int x=A[s];
do{
do i ++ ;while (1);
do j -- ;while(A[j]>x);
if(i<j){temp=A[i];(2);(3);}
}while(i<j);
A[a] =A[j];A[j] =x;
if(s<i-1) (4);
if(j+1<t) (5);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!