题目
#i nclude
void testf(int*p)
{
*p+=1;
}
main()
{
int *n,m[2];
n=m;
m[0]=1;
m[1]=8;
testf(n);
printf("Data v alue is %d ",*n);
}
------------------------------
B)
#i nclude
void testf(int**p)
{
*p+=1;
}
main()
{int *n,m[2];
n=m;
m[0]=1;
m[1]=8;
testf(&n);
printf(Data v alue is %d",*n);
}
下面的结果是程序A还是程序B的?
Data v alue is 8
那么另一段程序的结果是什么?
第1题
下面关于“联合”的题目的输出?
a)
#i nclude <stdio.h>
union
{
int i;
char x[2];
}a;
void main()
{
a.x[0] = 10;
a.x[1] = 1;
printf("%d",a.i);
}
第2题
A.4,3,2,1
B.4,3,6,7,2,1
C.4,3,6,2,1
D.1,2,3,4
第3题
有如下程序: #nclude<iostream> using namespace std; int main { void function(double val); double val; function(val); cout<<val; return 0; } void function(double val) } val=3;} 编译运行这个程序将出现的情况是()。
A.编译出错,无法运行
B.输出:3
C.输出:3.0
D.输出一个不确定的数
第4题
有如下程序:#nclude <iostream>using namespace std;class Base{ public:void fun1() {cout << "Base\n"; }virtual void fun2() {cout << "Base\n"; }};class Derived: public Base{ public:void fun1() {cout << "Derived\n"; }void fun2() {cout << "Derived\n"; }} void f(Base& b) { B. fun1(); B. fun2(); }int main(){Derived obj;f(obj);return 0;}
A.Base Base
B.Base Derived
C.Derived Base
D.Derived Derived
第5题
有如下程序:
nclude<iostream>
using namespace std;
class Animal{
public:
virtual char*getType()const{return“Animal”;}
virtual char*getVoice()const{return“Voice”;}
};
class Dog:public Animal{
public:
char*getType()const{rgturn“Dog”;}
char*getVoice()const{retum“Woof”;}
};
void type(Animal&A){cout<<a.getType();}
void speak(AnimalA){cout<<a.getVoice();}
int main(){
Dog d.type(D);tout<<“speak”;speak(D);cout<<endl;
return 0;
}
运行时的输出结果是【 】
第7题
A.语句1
B.语句2
C.语句3
D.语句4
第8题
有以下程序
#nclude<stdio.h>
#include<string.h>
main()
{ char a[5][10]={"china","beijing","you","tiananmen","welcome"};
int i,j;char t[10];
for(i=0;i<4;i++)
for(j=i+1;j<5;j++)
if(strcmp(a[i],a[j])>0)
{strcpy(t,a[i]);strcpy(a[i],a[j]);strcpy(a[j],t);}
puts(a[3]);
}
程序运行后的输出结果是
A.beijing
B.china
C.welcome
D.tiananmen
第9题
试题四(共15分)
阅读下列说明和C代码,回答问题1至问题3,将解答写在答题纸的对应栏内。
【说明】
模式匹配是指给定主串t和子串s,在主串t中寻找子串s的过程,其中s称为模式。
如果匹配成功,返回s在t中的位置,否则返回-1 。
KMP算法用next数组对匹配过程进行了优化。KMP算法的伪代码描述如下:
1.在串t和串s中,分别设比较的起始下标i=J=O
2.如果串t和串s都还有字符,则循环执行下列操作:
(1)如果j=-l或者t[i]-s[j],则将i和j分别加1,继续比较t和s的下一个字符;
(2)否则,将j向右滑动到next[j]的位置,即j =next[J]
3.如果s中所有字符均已比较完毕,则返回匹配的起始位置(从1开始);否则返回一1.
其中,next数组根据子串s求解。求解next数组的代码已由get_next函数给出。
【C代码】
(1)常量和变量说明
t,s:长度为悯铂Is的字符串
next:next数组,长度为Is
(2)C程序
include <stdio.h>
nclude <stdliB.h>
include <string.h>
/*求next【】的值*/
void get_next(int *next, char *s, int Is) {
int i=0,j=-1;
next[0]=-1;/*初始化next[0]*/
while(i< ils){/*还有字符*/
if(j=-1l ls[i]=s[j]){/*匹配*/
j++;
i++;
if(s[i]一s[jl)
next [i]- next[j];
else
Next[i]=j;
}
else
J= next[j];
}
}
int kmp(int *next, char *t ,char *s, int.lt, int Is )
{
inti= 0,j =0 ;
while (i<lt && (1 ) {
if(j=-1 II 2_) {
i++ ;
j ++ ;
} else
(3) :
}
if (j>= ls)
Retum (4)
else .
retum-1;
【问题1】(8分)
根据题干说明,填充C代码中的空(1)~(4).
【问题2】(2分)
根据题干说明和C代码,分析出kmp算法的时间复杂度为 (5)(主串和子的长度分别为It和Is,用O符号表示)。
【问题3】(5分)
根据C代码,字符串“BBABBCAC”的next数组元素值为 (6) (直接写素值,之间用逗号隔开)。若主串为“AABBCBBABBCACCD”,子串为“BBABBCAC则函数Kmp的返回值是 (7)
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!