A.英文
B.中文
C.法语
D.德语
第6题
编写一个类,该类的功能是可以根据给定的字符串(字符串的内容可以是中文,也可以是英文,字符串中单词之间可以有空格,也没有空格)和子串,计算出字符串中包含多少个子串。(要求:使用String类的方法。) 程序可以使用下面的框架: import java.util.Scanner; class CountSubString { //【变量声明】 //方法实现 void countSubString(String s, String substring) //s代表整个字符串,substring代表子串 { //【代码】 } } public class CountString { public static void main(String args[]) { Scanner reader=new Scanner(System.in); System.out.println("请输入字符串:"); String s=reader.nextLine(); System.out.println("请输入你要检索的子串:"); String substring=reader.nextLine(); CountSubString a=new CountSubString(); a.countSubString(s, substring); } } 例如,可以输入字符串“I like apple. The apple is decilious. Do you like apple?”和子串“apple”,程序的运行结果应该是检索到3个apple。 再例如,可以输入字符串“Ilikeapple.Theappleisdecilious.Doyoulikeapple?”和子串“apple”,程序的运行结果应该是检索到3个apple。 再例如,可以输入字符串"我喜欢苹果。苹果很美味。你喜欢苹果吗?"和子串"苹果",程序的运行结果应该是检索到3个“苹果”。
第7题
编写一个类,该类的功能是可以根据给定的字符串(字符串的内容可以是中文,也可以是英文,字符串中单词之间可以有空格,也可以没有空格)和子串,计算出字符串中包含多少个子串。(要求:使用String类的方法。) 程序可以使用下面的框架: import java.util.Scanner; class CountSubString { //【变量声明】 //方法实现 void countSubString(String s, String substring) //s代表整个字符串,substring代表子串 { //【代码】 } } public class CountString { public static void main(String args[]) { Scanner reader=new Scanner(System.in); System.out.println("请输入字符串:"); String s=reader.nextLine(); System.out.println("请输入你要检索的子串:"); String substring=reader.nextLine(); CountSubString a=new CountSubString(); a.countSubString(s, substring); } } 例如,可以输入字符串“I like apple. The apple is decilious. Do you like apple?”和子串“apple”,程序的运行结果应该是检索到3个apple。 再例如,可以输入字符串“Ilikeapple.Theappleisdecilious.Doyoulikeapple?”和子串“apple”,程序的运行结果应该是检索到3个apple。 再例如,可以输入字符串"我喜欢苹果。苹果很美味。你喜欢苹果吗?"和子串"苹果",程序的运行结果应该是检索到3个“苹果”。
第9题
替代关系:f(p)=p*11 mod 256(p是数组xx中某一个字符的ASCII值,f(p)是计算后新字符的ASCII值),如果原字符的ASCII值是偶数或计算后f(p)的值小于等于32,则该字符不变,否则将f(p)所对应的字符进行替代。
注意:部分源程序已给出,原始数据文件存放的格式是:每行的宽度均小于80个字符。
请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。
试题程序:
include <stdio.h>
include <string.h>
include <conio.h>
include <ctype.h>
unsigned char xx[50] [80];
int maxline = 0; /* 文章的总行数 */
int ReadDat(void);
void WriteDat(void);
void encryptChar()
{
}
main ( )
{
clrscr();
if (ReadDat ())
{
printf ("数据文件ENG9. IN不能打开 ! \n\007 ");
return;
}
encryptChar();
WriteDat();
}
int ReadDat (void)
{
FILE *fp;
int i= 0;
unsigned char *p;
if ((fp = fopen("ENG9.IN","r")) ==NULL) return 1;
while(fgets(xx[i], 80, fp) !=NULL)
{
p = strchr(xx[i], '\n');
if(p) *p = 0;
i++;
}
maxline = i;
fclose (fp);
return 0;
}
void WriteDat (void)
{
FILE *fp;
int i;
fp = fopen("PS9.DAT", "w");
for(i = 0; i < maxline; i++)
{
printf("%s\n", xx[i]);
fprintf(fp, "%s\n", xx[i]); }
fclose (fp);
}
第10题
替代关系;f(p)=p*11 mod 256 (p是数组xx中某一个字符的ASCII值,f(p)是计算后新字符的ASCII值),如果原字符是大写字母或计算后f(p)的值小于等于32,则该字符不变,否则将f(p)所对应的字符进行替代。
注意:部分源程序已给出。
原始数据文件的存放格式是:每行的宽度均小于80个字符。
请勿改动主函数main()、读函数ReadDat()和写函数WtiteDat()的内容。
试题程序:
include<conio.h>
include<stdio.h>
include<string.h>
include<ctype.h>
unsigned char xx[50] [80];
int maxline=0;
int ReadDat(void);
void writeDat(void);
void encryChar()
{
}
void main()
{
clrscr();
if(ReadDat())
{
print f ( "数据文件ENG49.IN 不能打开! \n\007" );
return;
}
encryChar();
WriteDat();
}
int ReadDat(void)
{
FILE *fP;
int i=0;
unsigned char *p;
if((fp=fopen("ENG49.IN","r"))==NULL)
return 1;
while(fgets(xx[i],80,fp)!=NULL)
{
p=strchr(xx[i],'\n');
if(p) *p=0;
i++;
}
maxline=i;
fclose(fp);
return 0;
}
void WriteDat()
{
FILE *fp;
int i;
fp=fopen("ps49.dat","w");
for(i=0;i<maxline;i++)
{
printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i]);
}
fclose(fp);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!