题目
阅读以下说明和C代码,将应填入(n)处的字句写在对应栏内。
[说明]
下面程序用来将打乱的单词还原为原来的次序,比如将rty还原为try。单词的原来次序存储于wordlist.txt文件中,原则上可用穷举法(rty对应的穷举为:rty、ryt、try、tyr、ytr、yrt),但考虑到破译速度,采用如下方法。
注意到单词列表中不存在组成字符完全相同的单词(如Hack12与Hack21包含完全相同的字符),因此将单词中的字符进行重组再进行比较,例如,try单词重组为rty(按ASCⅡ码顺序),这样不管打乱的单词是什么顺序,只要是由r、t、y三个字母组成的均破译为try,大大提高破译速度。程序中借助二叉排序树以进一步提高查找效率,二叉排序树左子树(如果有)上的节点对应的值均小于根节点的值,右子树(如果有)上的节点对应的值均大于根节点的值。
函数中使用的符号定义如下:
#define NumberofWords 1275//单词总数
#define MaxLength 10//最长单词所含字符数
char WordList[NumberofWords][MaxLength];//存储单词列表
int cmp(Node *q,Node *p);//q与p比较。p小,返回负值;P大返回正值:相等,返回0
typedef struct Node(//二叉树节点
char *eleLetters;//重组后的字符串
int index;//对应单词表中的下标
struct Node *lChiId,*rChiid;//左右子节点
}Node;
[C代码]
void reCompose(Node *p,char *temp)
//重纰,亦即将temp字符串中的字符升序排序,存储于p节点中
//采用直接插入排序法
{
char c;
strcpy(p->eleLetters,temp);//
int len=strlen(temp);
int i,j,k;
for(i=0;i<len-1;i++){
k=i;
for(j=i+1;j<lan;j++){
if(p->eleLetters[j]<P->eleLetters[k])k=J;
}
if((1) ){
C=P->eleLetters[i];
P->eleLetters[i]=P->eleLetters[k];
P->eleLetters[k]=c;
}//if
}//for
};
int find(Node &root,char *temp)
//在二叉排序树root中查找与temp匹配的单词。
//若匹配返回相应单词在WordList中下标;若查找失败,返回-1
{
Node *P,*q;
int flag;
P=(2);//临时存储
reCompose(p,temp);//将temp重组
q=&root;
while((flag=(3))&&q !=NULL){
if(flag<0){//搜索左子树
q=q->lChiid;
}else(//搜索右子树
q=q->rChild;
}
}//while
if(flag==0){//找到匹配的,保存下标
return (4);
}
}
if((5) ){//查找失败
printf("cant unscramble the following word:%s",temp);;
return -1;
}
};
(1)
第1题
() 阅读下列说明和JAVA代码,将应填入空(n)处的字句写在答题纸的对应栏内。【说明】 某中学开展中外中学生野外生存夏令营活动,由于中外学生的语言障碍,随队为外籍学员配置一名翻译。以下代码采用适配器(Adapter)模式模拟翻译适配器。其类图如下:
第2题
() 阅读下列说明和C++代码,将应填入空(n)处的字句写在答题纸的对应栏内。【说明】 某中学开展中外中学生野外生存夏令营活动,由于中外学生的语言障碍,随队为外籍学员配置一名翻译。以下代码采用适配器(Adapter)模式模拟翻译适配器。其类图如下:
第3题
阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。
[说明]
以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。
[JAVA代码]
//定义自己的异常类
class CCircleException extends Exception
{
}
// 定义类 CCircle
class CCircle
{
private double radius;
public void setRadius (double r ) (1)
{
if (r<0 ) {
(2)
}
else
(3)
}
Public void show () {
System. out. println ("area="+3.14*radius*radius );
}
}
public class ciusample
{
public static void main (String args[] )
{
CCircle cir=new CCircle();
(4) {
cir. setRadius (-2.0 )
}
(5)
{
System. out. println (e+" throwed" ) ;
}
cir. show() ;
}
}
第4题
●试题八
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。
【程序】
#include<stdio.h>
main()
{FILE*fp;
charstr[100];inti=0;
if((fp=fopen("text.txt" (1) ))==NULL)
{printf("can't open this file.\n");exit(0);}
printf("input astring:\n");gest(str);
while(str[i])
{if(str[i]>=′a′ && str[i]<=′z′)
str[i]= (2) ;
fputc(str[i], (3) );
i++;
}
fclose(fp);
fp=fopen("test.txt", (4) );
fgets(str,100,fp);
printf("%s\n",str);
(5) ;
}
第5题
阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序为求行列式X(5,5)的值S。
【Visual Basic代码】
Private Function col (byval x (5,5 ) as integer ) as long
dim fesult as long
dim temp as long
dim I as integer
dim j as integer
dim k as imeger
result = 0
for I = to 5
(1)
for j = 1 to 5
if I+j>6 then
k= (1+j ) mod 5
else
k=1
endif
temp=temp*x (k,j )
(2)
result=(3)
(4)
(5)
End function
第6题
阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。
【程序】
include < stdio. h >
main()
{ FILE * fp;
char str[100]; int i=0;
if((fp=fopen("text.txt"(1))) ==NULL)
{ printf("can't open this file. \n") ;exit(0) ;}
printf(" input astring: \n" ); gest(str);
while(str[i] )
{ if(str[i] >='a' && str[i] <='z')
str[i]=(2);
fputc(str[i],(3));
i++;
}
fclose(fp);
fp=fopen(" test.txt",(4));
fgets(str, 100, fp);
printf("%s\n" ,str);
(5);
}
第7题
阅读以下说明、Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
本程序输出10000之内的所有完全数。完全数是指等于其所有因子和(包括1,但不包括这个数本身)的数。例如:6=1×2×3,6=1+2+3,则6是一个完全数。
【程序】
public class PerfectNum
{
Public static void main(String args[])
{
int count=1;
for(int i=1; i<10000; i++)
{
int y=0;
for(int j=1; j<i; j++)
if((1))
y=(2)
if((3))
{
System.out.print((4) +String.valueOf('\t'));
(5)
If(count%3==0)
System.out.printin();
}
}
}
第8题
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
[说明]
编写一个字符界面的Java Application 程序,接受用户输入的10个整数,并输出这10个整数的最大值和最小值。
[Java 代码]
import java. io.* ;
public class abc
{
public static void main ((1))
{int i, n=10, max=0, min=0, temp=0;
try {
BufferedReader br = new BufferedReader (
new InputStreamReader (System.in ) );
max = min =Integer. parselnt (br. readLine () );
}. (2) (IOExccption e ) {} ;
for (i=2 ; i<=n ; i++ ) {
try {
BufferedReader br = new (3) (
new InputStreamReader (System. in ) );
temp =(4) (br. readLine ());
if (temp>max ) max=temp;
if (temp<min) (5)
} catch (IOException e ) {};
}
System.out.println ("max="+max+"\nmin="+min );
}
}
第9题
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
下面程序完成从键盘读入一个字符串,然后采用parseInt方法将其转换为一个相应的整数。
import java.io.*;
public class testThrows{
public static (1) readString() (2) IOException{
int ch;
String r="";
boolean done=false;
while((3)){
ch=System.in.read();
if(ch<0 || ch=0xd) //处理回车符中第一个符号
done=true;
else
r=r+(char)ch;
}
return r;
}
public static void main(Stling args[]){
String str;
(4) {
str=readString();
} (5) (IOException e){
System.out.println("error");
return;
}
System.out.println("input integer: "+Integer.parselnt(str));
}
}
第10题
阅读以下说明和Visual Basic代码,将应填入(n)处的字句写在对应栏内。
【说明】
以下代码实现了当用户退出界面时,判断TextEdit中的文字是否发生改变,弹出对话框判断,让用户选择是否保存文件或取消退出界面操作。阅读下面的代码,将其补充完整。
【代码7-1】
Begin VB.Form. Forml
//...窗体描述(略)
Begin VB.TextBox TextEdit
Height = 1830
Left = 180
Tablndex = 0
Text = "TextEdit"
Top = 360
Width = 3885
End
//...窗体描述(略)
End
【代码7-2】
Dim txtchange As Boolean
Dim myval As String
Private Sub Form. Load ()
TextEdit.Text: "CIU, 中国软考联盟!"
txtchange = False
End Sub
【代码7-3】
Private Sub TextEdit_Change ()
Static notchange As Boolean
(1)
notchange = Tree
End Sub
Private Sub Form_Unload (Cancel As Integer )
Dim myval As String
If (2) Then
myval = MsgBox ("保存文件的更改吗?", vbYesNoCancel, "提示信息" )
If (3) Then
MsgBox "保存成功"
End
End If
If (4) Then End
If (5) Then Cancel = 1
End If
End Sub
第11题
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
java.util库中提供了Vector模板类,可作为动态数组使用,并可容纳任意数据类型。该类的部分方法说明如下表所示:
【Java代码】
import (1);
public class JavaMain {
static private final int (2)= 6;
public static void main(String[] args){
Vector<Integer> theVector = new Vector< (3) >();
// 初始化 theVector, 将theVector的元素设置为0至5
for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)
theVector.add((4));
showVector(theVector); // 依次输出theVector中的元素
theVector.removeElementAt(3);
showVector(theVector);
}
public static void showVector(Vector<Integer> theVector
if (theVector.isEmpty()) {
System.out.println("theVectcr is empty.");
return;
}
for (int loop = 0; loop < theVector.size(); loop++)
System.out.print(theVector.get(loop));
System.out.print(", ");
}
System.out.println();
}
}
该程序运行后的输出结果为:
0,1,2,3,4,5
(5)
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!