在VB中,表达式String(2,"99")的结果是( )(说明:生成长度为2的字符,字符内容为9,String(3,"99")="999")
A.9
B.99
C.999
D.9999
第1题:
下列给定的程序中,函数fun()的功能是;将s所指字符串中出现的n所指字符串全部替换成t2所指字符串,所形成的新的字符串放在w所指的数组中。在此处,要求t1和t2所指字符串的长度相同。例如:当s所指字符串中所指的内容为 abcdabfab,t1所指字符串中的内容为ab,t2所指字符串中的内容为99时,结果在w所指的数组中的内容应为99cd99f99。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
/*************found**************/
int fun (char *s, char *t1, char *t2, char *w)
{
int i; char *p,*r,*a;
strcpy(w,s);
while (*w)
{p=w; r=t1;
/*************found**************/
while (r)
if (*r= =*p) {r++;p++;}
else break;
if (*r= ='\0')
{a=w; r=t2;
/*************found**************/
while (*r){*a=*r;a++;r++}
w+=strlen(t2);
}
else w++;
}
}
main()
{char s[100],t1[100],t2[100],w[100];
clrscr();
printf("\nPlease enter string S: ");
scanf("%s",s);
printf("\nPleaseentersubstring t1: ");
scanf ("%s", t1);
printf("\nPlease enter substring t2: ");
scanf ("%s",t2);
if (strlen(t1)= =strlen(t2))
{
fun (s,t1,t2,w);
printf("\nThe result is : %s\n",w);
}
else printf("Error : strlen(t2)\n");
}
第2题:
对于两个字符串s1、s2,表达式s1==s2是判断它们()是否相同
A.内容
B.地址
C.首字符
D.长度
第3题:
字符串s长度为奇数,则显示中间字符的表达式为?
A.s[len(s)/2]
B.s[(len(s) - 1)/2]
C.s[len(s)/2 + 1]
D.s[len(s)/2 - 1]
E.s[(len(s) + 1)/2]
第4题:
下列给定程序中,函数proc的功能是:首先把b所指字符串中的字符按逆序存放,然后将str1所指字符串中的字符和Str2所指字符串中的字符,按排列的顺序交叉合并到str所指数组中,过长的剩余字符接在str所指数组的尾部。例如,当str1所指字符串中的内容为ABCDEFG,str2 所指字符串中的内容为1234时,str所指数组中的内容应该为A483C2D1EFG;而当str1所指字符串中的内容为1234,str2所指字符串中的内容为ABCEDFG时,str所指数组中的内容应该为1G2F31:4DCBA。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdlib.h> include<conio.h> include<stdio。h> include<string.h> void proc(char*strl,char*str2,char*str) { int i,j;char ch; i=0;j=strleu(str2)-1; //****found**** while(i>j) { ch=str2[i];str2[i]=str2[j];str2[j]=ch; i++;j--; } while(*str1||*str2) { if(*str1){*str=*str1;str++;str1++;) if(*str2){*str=*str2;str++;str2++;) } //****found**** *str=0: } void main { char s1[100],s2[100],t[200]; system("CLS"); printf("\nEnter s1 string:"); scanf("%s",sl); printf("\nEnter s2 string:"); scanf("%s",s2); proc(s1,s2,t); printf("\nThe result is:%s\n",t); }
(1)错误:while(i>j)
正确:while(i<j)
(2)错误:*str=0;
正确:*str='\0 ';
【解析】由函数proc可知,变量i和j分别存放的是字符串str前面和后面第i个字符的位置,当i<j时,两个位置的字符交换。因此,“while(i>j)”应改为“while(i<j)”;交叉合并完成后,要为新的字符串添加结束符,因此,“*str= 0;”应改为“*str='\0';”,
第5题:
【单选题】9.设S为一个长度为n的字符串,其中的字符各不相同,则S中的互异的非平凡子串(非空且不同于S本身)的个数为()。
A.2n-1
B.n2
C.(n2/2)+(n/2)
D.(n2/2)+(n/2)-1