2010年春季江苏省计算机二级C语言真题(笔试)(2)

2019-04-22 10:11

void fun(char *p1,char *p2) {char t; while(p1

{t=*p1;*p1=*p2;*p2=t; p1+=2,p2-=2; } }

13.以下程序运行时输出至到屏幕的结果第一行是(17) ,第二行是(18) 。 #include

typedef struct{int x,y;}direction;

int visible(direction s,direction A,direction B,direction C) {direction p1,p2; int d;

p1.x=B.x-A.x; p1.y=B.y-A.y; p2.x=C.x-A.x;

p2.y=C.y-A.y;

d=s.x*p1.x*p2.x+s.y*p1.y*p2.y; printf(\ return d>0; }

void main()

{char *ss[]={\

direction s={1,1},T={1,1},A={0,0},B={2,1}; puts(ss[visible(s,T,A,B)]); } ● 完善程序

14.以下程序的功能是:统计一个字符串中数字字符\到\各自出现的次数,统计结果保存在数组count中。例如,如果字符串为\则统计结果为:1:2 2:1 3:2 4:35:2 6:1 7:1 8:1 9:1。试完善程序以达到要求的功能。 #include

void fun(char *t,int count[]) { char *p=t;

while( _____(19)_____ ) { if(*p>='0' && *p<='9')

count[_____(20)_____]++; p++; } }

void main()

{char s[80]=\ fun(s,count); for(i=0;i<10;i++)

if(count[i]) printf(\ \

}

15.下列程序的功能是对a数组a[0]~a[n-1]中存储的n个整数从小到大排序。排序算法是:第一趟通过比较将n个整数中的最小值放在a[0]中,最大值放在a[n-1]中;第二趟通过比较将n个整数中的次小值放在a[1]中,次大值放在a[n-2]中;......,依次类推,直到待排序序列为递增序列。试完喜程序以达到要求的功能。 #include

#define N 7 void sort(int a[],int n) {int i,j,min,max,t; for(i=0;i<___(21)___;i++) { ______(22)______ ; for(j=i+l;j

if(a[j]

else if(a[j]>a[max])max=j; if(min!=i)

{t=a[min];a[min]=a[i];a[i]=t;}

if(max!=n-i-1) if(max==i)

{t=a[min];a[min]=a[n-i-1];a[n-i-1]=t;} else

{t=a[max];a[max]=a[n-i-1];a[n-i-1]=t;} } }

void main()

{int a[N]={8,4,9,3,2,1,5},i; sort(a,N);

printf(\ for(i=0;i printf(\ }

16.下列程序中函数find_replace的功能是:在s1指向的字符串中查找s2指向的字符串,并用s3指向的字符串替换在s1中找到的所有s2字符串。若sl字符串中没有出现s2字符串,则不做替换并使函数返回0,否则函数返回1。试完善程序以达到要求的功能。 #include

#include

int find_replace(char s1[],char s2[],char s3[]) { int i,j,k,t=0; char temp[80]; if(s1[0]=='\\0'||s2[0]=='\\0')return t; for(i=0;s1[i]!='\\0';i++)

{ k=0; j=i;

while(s1[j]==s2[k]&&s2[k]!='\\0') { j++;

___(23)_________ ; }

if(s2[k]=='\\0')

{ strcpy(temp,&s1[j]);

___________(24)________; i=i+strlen(s3);

_______(25)_________; t=1; } }

return t; }

void main()

{char line[80]=\ char substr1[10]=\ int k;

k=find_replace(line,substr1,substr2); if(______(26)_______) puts(line); else

printf(\

}

17.设hl和h2分别为两个单链表的头指针,链表中结点的数据结构为: typedef struct node {int data;

struct node *next; }NODE; .

sea_del 函数的功能是:删除hl指向的链表中首次出现的与h2指向的链表中数据完全匹配的若干个连续结点,函数返回hl指向链表的头指针。例如,初态下,hl指向链表和h2指向链表如下图所示:试完善函数sea_del以达到要求的功能。 NODE *sea_del(NODE *h1,NODE *h2) {NODE *p,*ph,*q,*s;

ph=NULL;p=q=h1; s=h2; if(h1==NULL||__(22)__) return h1; while(p!=NULL&&s!=NULL) {while(q->data==s->data&&q&&s) { q=q->next; s= __(28)__;

}

if(s!=NULL) /*失配时,h1起始结点后移,h2从首结点开始*/ { ph=p;

p=q=p->next; s=__(29)__; }

else 、

if(ph==NULL) h1=q; else ph->next=q; }

__(30)__ ; }

答案

第一部分 计算机基础知识

1.D 2.B 3.C 4.B 5.A 6.D 7.C 8.B 9.D 10.D 11.D 12.B 13.B 14.B 15.C 16.A 17.B 18.C 19.C 20.A

第二部分 C语言程序设计

21.D 22.D 23.A 24.B 25.C 26.D 27.A 28.B 29.C 30.B

(1)1/3.0 (2)G (3)2 (4)5 (6)10 (7) 2, 1 (8)13 11 12 (9) 5 (11)8 (12)221 (13)1 1 (14)1 3 3 1 (16)14325 (17)-1 (18)invisible (19)*p (21)n/2 (22)min=max=I (23) k++ (24)strcpy(&s1[i],s3) strcat(s1,temp)

(26)k (27)h2==NULL (28)s->next (29)h2 (30)return h1

(5)a=3 (10)7

(15)321 (20)*p-48 (25)


2010年春季江苏省计算机二级C语言真题(笔试)(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:组合类紧固件制造项目可行性研究报告方案(可用于发改委立项及银

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: