[计算机类试卷]软件水平考试(初级)程序员下午(应用技术)模拟试卷30及答案与解析.doc
《[计算机类试卷]软件水平考试(初级)程序员下午(应用技术)模拟试卷30及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]软件水平考试(初级)程序员下午(应用技术)模拟试卷30及答案与解析.doc(16页珍藏版)》请在麦多课文档分享上搜索。
1、软件水平考试(初级)程序员下午(应用技术)模拟试卷 30 及答案与解析 1 阅读下列算法说明和算法,将应填入 (n)处的语句写在对应栏内。 【说明】 为了减少直接插入排序关键字的比较次数,本算法使用了二分 (折半 )插入法对一个无序数组 R1n进行排序。排序思想是对一个待插入元素,先通过二分法 (折半 )找到插入位置,后移元素后将该元素插入到恰当位置。 (假设 R中的元素互不相同 ) 算法 1变量声明 X: Data Type i,j,low, high,mid,r:0n 2每循环一次插入一个 Ri 循环: i以 1为步长,从 2到 n,反复执行。 (1)准备 XRi;(1); highi -
2、1; (2)找插入位置 循环:当 (2)时,反复执行。 (3) 若 X.key Rmid.key 则 highmid -1; 否则 (4) (3)后移 循环: j以 -1为步长,从 (5),反复执行。 Rj+1Rj (4)插入 RlowX 3算法结束 2 阅读以下函数说明和 C语言函数,将应填入 (n)处的语句写在对应栏内。 【函数 2.1说明】 有 1、 2、 3、 4四个数字,输出由这些数字组成的互不相同且无重、复数字的三位数。 【函数 2.1】 main() int i,j,k; printf(“n“); for(1) /*以下为三重循环 */ for(j=1; j 5;j+) for
3、(k=1;k 5;k+) if (2) /*确保 i, j, k 三位互不相同 */ printf(“%d,%d,%dn“,i,j,k); 【函数 2.2说明】 计算并输出 100之内的素数,每行输出 10个,超过 10个则换行。 【函数 2.2】 #include stdio.h #include “math.h“ #define N 101 main() int i,j,line,aN; for(i=2;i N;i+)(3); for(i=2;i sqrt(N);i+) for(j=i+1;j N;j+) if(ai!=0 printfCn“); for(i=2,line=0;i N;i+
4、) if(ai!=0) prinff(“%5d“,ai); (5); if(line=10) prinff(“n“); line=0; 3 阅读以下说明和 C语言函数,将应填入 (n)处 的语句写在对应栏内。 【说明】 设串 s和串 t采用顺序存储结构,编写函数实现串 s和串 t的比较操作,要求比较结果包括大于、小于和等于 3种情况。 【函数】 int StrCompare(SStrType s, SStrType t) int n=s.length, m=(1), i,j,tag; i=0; j=0; while(2) if(3) i+; j+; else if(s.stri t.strj)
5、 tag=1; return tag; else tag=-1; return tag; if(n=m) tag=0; else if(4) tag=1; else if(n m) tag=-1; (5); 4 阅读以下说明和 C语言函数,将应填入 (n)处的语句写在对应栏内。 【说 明】 著名的四色定理指出任何平面区域均可以用 4种颜色着色,使相邻区域着不同的颜色。本程序对给定的区域图找出所有可能的不超过 4种颜色的着色方案。 【函数】 # include stdio.h #define N 10 /*要着色的 N个区域 */ void output(int color) /*输出一种着色方
6、案 colori的值为区域 i所着颜色 */ int i; for (i=0; i N; i+) printf(“%4d“, colori); printf(“n“); int back(int *ip, int colorj /*回溯 */ int c=4; while (c=4) if (*ip =0) return 0: -(*ip); c=(1); color*ip=-1; return c; /*检查区域 i,考查 c种颜色的可能性 */ int colorOK(iht i, int c, int adjN, int color) int j; for(j=0; j i; j+) i
7、f (2) return 0; return 1; /*为区域 i选一种可着的颜色 */ int select(int i, int c, int adjN, int color) /*寻找各种着色方案 adjij=1表示区域 i与区域 j不相邻 */ int k; for (k=c; k =4; k+) /*4种颜色 */ if (colorOK(3) return k; return 0; int coloring(int adjN) int colorN, i, c, cnt; for (i=0; i N; i+) colori=-1: i=c=0; cnt=0; while (1) i
8、f (c=(4)=0) c=back( if (c=0) return cnt; else (5); i+; if(i=N) output(color); +cnt; c=back( else c=0; void main() int adjNN= 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0
9、, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0 ; printf(“共有 %d 组解 .n“, coloring(adj); 5 阅读以下说明及 C+程序代码,将应填入 (n)处的语句写在对应栏内。 【说明】 本程序的功能是实现任意两个大整数的乘法运算,例如: 输入整数 1: 8934793850094505800243958034985058 输入整数 2: 234584950989689084
10、095803583095820923 二者之积: 209596817742739508050978890737675662366433464256830959194834854876 8534 【 C+代码】 #include iostream.h const int MAXINPUTBIT=100; const int MAXRESULTBIT=500; class LargeNumber int i,j; int temp; int oneMAXINPUTBIT+1; int onebit; /one的位数 int twoMAXINPUTBIT+1; int twobit; /two的位数
11、 int resultMAXRESULTBIT+1; public: LargeNumber(); LargeNumber(); int inputone(); /出错返叫 0,否则返回 1 int inputtwo(); /同上 void multiplication(); /乘 void clearresult(); /清零 void showresult(); /显示 ; LargeNumber LargeNumber() for(i=0;i =MAXINPUTBIT;i+) onei=0; twoi=0; onebit=0; twobit=0; inputone(); inputtwo
12、(); LargeNumber LargeNumber() int LargeNumber inputone() char NumberMAXINPUTBIT+1; cout “Please enter one:“; cin Number; i=0; j=MAXINPUTBIT; while(Numberi!=0) i+; onebit=i; for(i-;i =0;i-,j-) if(int(Numberi) =48 /由字符转换为数字 else return 0; return 1; int LargeNumber inputtwo() char NumberMAXINPUTBIT+1;
13、cout “Please enter two:“; cin Number; i=0; j=MAXINPUTBIT; while(Numberi!=0) i+; twobit=i; for(i-;i =0;i-,j-) if(int(Numberi) =48 /由字符转换为数字 else return 0; return 1; void LargeNumber multiplication() /乘法 clearresult(); int m; for(i=MAXINPUTBIT;i =0;i-) temp=twoi; for(j=(2),m=MAXINPUTBIT;m =0;m-,j-) re
14、sultj+=temp*onem; if(resultj 9) resultj-1+=resultj/10; (3); cout “one*two=“; showresult(); void LargeNumber showresult() i=0; while(resulti=0 if(i MAXRESULTBIT) cout “0“; /输出 0 for(;i =MAXRESULTBIT;i+) cout (4); cout endl; void LargeNumber clearresult() for(i=0;i =MAXRESULTBIT;i+) (5); void main() L
15、argeNumber a; a.multiplication(); 6 阅读以下说明和 Java代码,回答问题 1和问题 2,将解答填写在对应栏内。 【 Java代码】 class usethread implements (1) int num usethread(int n) num=n; public void (2) for(int i=0;i 3;i+) System.out.println(“running:“+num); System.out.println(“finished:“+num); public class multhread public static void m
16、ain(String args) (3) InterruptedException Thread m1=new Thread(new usethread(1); Thread m2=new Thread(new usethread(2); m1.start(); m2.start(); m1.join(); m2.join(); 【问题 1】 补充完整上面 Java代码中 (n)处。 【问题 2】 写出上面 Java代码运行的结果。 软件水平考试(初级)程序员下午(应用技术)模拟试卷 30 答案与解析 1 【正确答案】 (1)low1 (2)low =high (3)midint(low+hi
17、gh)/2) (4)lowmid+1 (5)i -1到 low 【试题解析】 本题考查使用二分插入法对无序数组排序的伪码实现。 在做题前,我们需要先大概明白二分插入法的基本思想和步骤,其基本思想是(设 Rlow, , high是当前的插入区间 ): (1)将要插入的数取出放在 X中; (2)确定区间的中点位置: mid=(low+high)/2; (3)确定插入位置,将待插入的 k值与 Rmid.key比较,具体方法如下: 若 Rmid.key k,则由排序后表的有序性可知 Rmid, , n.key均大于 k,因此,插入区间是左子表 Rlow, , high,其中 high=mid-1。 若
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 软件 水平 考试 初级 程序员 下午 应用技术 模拟 30 答案 解析 DOC
