更多"字符串“computer”中长度为3的子串有()个。"的相关试题:
[简答题]请编写一个函数proc( ),它的功能是:比较两个字符串的长度(不得调用C语言中求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相等,则返回第1个字符串。
例如,若输入jiangxi<CR>
beijing<CR>(<CR>为回车键)
则函数返回jiangxi。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
char * proc(char *s, char *t)
void main( )
char a[20], b[10], *p, *q;
printf("Input 1th string: ");
gets(a);
printf("Input 2th string: ");
gets(b);
printf("%s", proc(a,b));
[单项选择]对于字符串“software”,其长度为2的子串共有()个。
A. 4
B. 7
C. 28
D. 56
[多项选择]填空题
请补充main函数,该函数的功能是:从一个字符串中截取前面若干个给定长度的子字符串。其中,str1指向原字符串,截取后的字符存放在str2所指的字符数组中,n中存放需截取的字符个数。
例如:当str1=“cdefghij”,然后输入4,则str2=“cdef”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
#define LEN 80
main( )
{
char str1[LEN],str2[LEN];
int n,i;
clrscr( );
printf("Enter the string:/n");
gets(str1);
printf("Enter the position of the string
deleted:");
scanf(【1】);
for(i=0;i
[填空题]请补充main函数,该函数的功能是:从一个字符串中截取前面若干个给定长度的子字符串。其中,str1指向原字符串,截取后的字符存放在str2所指的字符数组中,n中存放需截取的字符个数。
例如:当str1=“cdefghij”,然后输入4,则str2=“cdef”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define LEN 80
main( )
char str1[LEN],str2[LEN];
int n,i;
clrscr( );
printf("Enter the string:/n");
gets(str1);
printf "Enter the position of the string deleted:");
scanf( 【1】 );
for(i=0;i<n;i++)
【2】
str2[i]=‘/0’;
printf("The new string is:%s/n", 【3】 );
[单项选择]若字符串s的长度为n(n>1),且其中的字符互不相同,则s的长度为2的子串有()个。
A. n
B. n-1
C. n-2
D. 2
[单项选择]
对于求取两个长度为n 的字符串的最长公共子序列(LCS)问题,利用(57 )策略可以有效地避免子串最长公共子序列的重复计算,得到时间复杂度为O(n2)的正确算法。串<1,0,0,1,0,1,0,1>和<0,1,0,1,1,0,1,1>的最长公共子序列的长度为 (58) 。
(57)处填()。
A. 分治
B. 贪心
C. 动态规划
D. 分支-限界
[简答题]编写一个函数findStr( ),该函数统计一个长度为2的子字符串在另一个字符串中出现的次数。例如,假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为"as",函数返回值是6。
函数ReadWrite( )实现从文件in.dat中读取两个字符串并调用函数findStr( ),最后把结果输出到文件out.dat中。
注意:部分程序已经给出。
请勿改动主函数main( )和其他函数中的任何内容,仅在函数findStr( )的花括号中填入你编写的若干语句。
#include <stdio.h>
#include <string.h>
#include <conio.h>
int findStr(char *str,char *substr)
main( )
char str[81],substr[3];
int n;
clrscr( );
printf("输入原字符串");
gets(str) ;
printf("输入子字符串:");
gets(substr);
puts(str);
puts(substr);
n=findStr(str, substr);
printf("n=%d/n", n);
ReadWrite( );
ReadWrite( )
char str[81],substr[3],ch;
int n, len,i=0;
FILE *rf, *wf;
rf=fopen("in.dat", "r");
wf=fopen("out.dat", "w");
while(i<25)
fgets(str, 80, rf);
fgets(substr, 10, rf);
len=strlen(substr)-1;
ch=substr[l
[填空题]已知substr(s,i,len)函数的功能是返回串s中第i个字符开始长度为len的子串,strlen(s)函数的功能是返回串s的长度。若s="ABCDEFGHUK",t="ABCD",执行运算substr(s,strlen(t),strlen(t))后的返回值为______。
[单项选择]设S是一个长度为5的字符串,其中的字符各不相同,则计算S中互异的非平凡子串(非空且不同于S本身)数目的算式为()
A. 5+4+3+2+1
B. 5+4+3+2
C. 4+3+2+1+1
D. 4+3+2+1
[多项选择]请编写函数proc( ),该函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。
例如,若字符串数组中的M个字符串为:
A. 则合并后的字符串内容应该是BCDEFGCDEFGHI
B. void main()char str[M][N]=("", "BCDEFG", "CDEFGHI"), i;
[简答题]编写一个函数,用该函数可以统计一个长度为3的字符串在另一个字符串中出现的次数。例如,假定输入字符串“the abcthe they have theren”,子字符串为“the”,则应输出4。
注意:部分源程序在文件PROC2.CPP中。
请勿改动主函数和其他函数中的任何内容,仅在fun( )的花括号中填入编写的若干语句。
部分源程序如下:
//PROC2.CPP
#include <iostream>
using namespace std;
#define MAX 100
int fun(char *str,char *substr);
int main( ){
char str[MAX],substr[3];
int n;
cout<<"Please Input the source String/n";
cin>>str;
cout<<"Please Input the subString/n";
cin>>substr;
n=fun(str, substr);
cout<<"The counter is: "<<n<<end1;
return 0;
}
int fun(char *str,char *substr)
{
//******
}
[多项选择]请编写函数fun( ),该函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按J顷序合并组成一个新的字符串。
例如,若字符串数组中的M个字符串为
A. 则合并后的字符串内容应该是BBBBBBBCC
B. char w [M] [N] ="", "BBBBBBB", "CC", i;
C. puts (w[i]);
D. printf (" /n ");
E. fun (w, a);
F. printf ("The A string: /n ");
G. printf("%s ",a);
H. printf("/n/n ");
[多项选择]函数readDat( )是从文件IN.DAT中读取20行数据存放到字符串数组XX中(每行字符串长度均小于80)。请编制函数jsSort( ),其功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组XX中,最后调用函数writeDat( )把结果XX输出到文件OUT.DAT中。条件:从字符串中间一分为二,左边部分按字符的ASCⅡ值降序排序,右边部分按字符的ASCⅡ值升序排序。如果原字符串长度为奇数,则最中间的字符不参加排序,字符仍放在原位置上。
例如,位置 0 1 2 3 4 5 6 7 8
源字符串 a b c d h g f e
1 2 3 4 9 8 7 6 5
则处理后字符串d c b a e f g h
4 3 2 1 9 5 6 7 8
注意:部分源程序存在文件PROG1.C文件中。请勿改动数据文件IN.DAT中的任何数据、主函数main( )、读函数readDat( )和写函数writeDat( )的内容。
[试题程序]
#include
#include
char XX[20][80];
void readDat( );
void writeDat( );
void jsSort( )
void main( )
readDat( );
jsSort( );
writeDat( );
void readDat( )
FILE *in;
int i=0;
char *p;
in=fopen("in.dat","r");
while(i<20&&fgets(xx[i],80,in)!=NULL)
p=strchr(xx[i],’/n’);
if(p) *P=0;
i++;
fclose(in);
void writeDat( )
FILE *out;
int i;
out=fop