第五届全国ITATC语言程序设计A卷答案.docx
- 文档编号:10761426
- 上传时间:2023-05-27
- 格式:DOCX
- 页数:10
- 大小:16.65KB
第五届全国ITATC语言程序设计A卷答案.docx
《第五届全国ITATC语言程序设计A卷答案.docx》由会员分享,可在线阅读,更多相关《第五届全国ITATC语言程序设计A卷答案.docx(10页珍藏版)》请在冰点文库上搜索。
第五届全国ITATC语言程序设计A卷答案
第五届全国ITAT教育工程就业技能大赛复赛试题
C语言程序设计A卷
1、编程解决如下数学问题:
有12升水,怎样利用一个8升和一个5升的容器将水分为两个6升?
要求以如下格式打印出分水步骤。
(20分)
a12b8c5
1200
***(“*”表示当前状态下每个容器的盛水量)
......
066
#include
voidmain()
{
inta12=12,b8=0,c5=0;
printf("a12b8c5\n%-5d%-4d%-4d\n",a12,b8,c5);
while(a12!
=6||b8!
=6)
{
if(b8==0)
{
a12-=8;b8=8;
}
elseif(b8==8)
{
b8-=(5-c5);c5=5;
}
elseif(c5==0)
{
if(b8>=5)
{
b8-=5;c5=5;
}
else
{
c5=b8;b8=0;
}
}
elseif(c5==5)
{
a12+=5;c5=0;
}
printf("%-5d%-4d%-4d\n",a12,b8,c5);
}
}
2、编程实现:
有二维数组a[3][3]={{5.4,3.2,8},{6,4,3.3},{7,3,1.3}},将数组a的每一行元素均除以该行上的主对角元素(第1行同除以a[0][0],第2行同除以a[1][1],...),按行输出新数组。
(20分)
#include
intmain()
{
doublea[3][3]={{5.4,3.2,8},{6,4,3.3},{7,3,1.3}};
double(*p)[3]=a,div;
size_ti,j;
for(i=0;i<3;i++)
{
div=*(*(p+i)+i);
for(j=0;j<3;j++)
*(*(p+i)+j)/=div;
}
for(i=0;i<3;i++)
{
putchar('\n');
for(j=0;j<3;j++)
printf("%lf",a[i][j]);
}
putchar('\n');
return0;
}
3、编程:
设x取值为区间[1,20]的整数,求函数f(x)=x-sin(x)-cos(x)的最大值,要求使用自定义函数实现f(x)功能。
(20分)
#include
#include
#include
#definePI3.141592
doublefunc(inti)
{return1-sin(i)-cos(i);}
doubleOperation()
{
inti;
doubletmax,max;
max=func
(1);
for(i=PI/2;i<20;i+=3*PI/2)
if(max max=func(i); tmax=func(20)>max? func(20): max; returntmax; } intmain() { printf("Themaximumfunctionvaluewhenxisbettween[1,20]: \n"); printf("%lf\n",Operation()); return0; } 4、编写函数fun,通过指针实现将一个字符串反向。 要求主函数输入字符串,通过调用函数fun实现输入字符串反向。 (20分) #include #include #include char*fun(char*q) { chartemp; inti; intlen=strlen(q); for(i=0;len-i-1>i;i++) { temp=*(q+i); *(q+i)=*(q+len-i-1); *(q+len-i-1)=temp; } returnq; } intmain() { char*p=(char*)malloc(200*sizeof(char)); printf("pleaseinputthestring: \n"); scanf("%s",p); fun(p); printf("thestringthathasbeeninversed: \n"); printf("%s\n",p); } 5、已知学生三门课程基本信息如下。 请使用结构体编程,计算学生三门课程平均成绩后,列表输出学生的姓名、数学、英语、计算机、平均分信息,并按平均分排序。 (20分) 姓名数学英语计算机 Mary9310088 Jone829090 Peter917671 Rose1008092 #include #include typedefstructstudent { charname[20]; floatmath; floatEnglish; floatcomputer; floataverage; }student; studentstu[4]={{"Mary",93,100,88},{"Jone",82,90,90},{"Peter",91,76,71},{"Rose",100,80,92}}; voidprint(studentstu[],intn) { inti; printf("theinformationofstudentsbeforesorted: \n"); for(i=0;i printf("%s%.0f%.0f%.0f%.1f\n",stu[i].name,stu[i].math,stu[i].English,stu[i].computer,stu[i].average); putchar('\n'); } intcomp(constvoid*p1,constvoid*p2) { return*(constfloat*)p1-*(constfloat*)p2; } intmain() { floattemp[4]; intorder[4],i,j; for(i=0;i<4;i++) stu[i].average=(stu[i].math+stu[i].English+stu[i].computer)/3; print(stu,4); for(i=0;i<4;i++) temp[i]=stu[i].average; qsort(temp,4,sizeoftemp[0],comp); for(i=0;i<4;i++) for(j=0;j<4;j++) if(temp[i]==stu[j].average) { order[i]=j; break; } printf("theimformationofstudentaftersorted: \n"); for(i=0;i<4;i++) { j=order[i]; printf("%s%.0f%.0f%.0f%.1f\n",stu[j].name,stu[j].math,stu[j].English,stu[j].computer,stu[j].average); } return0; } 6、附加题: 编程实现输入一串英文,统计其中各单词出现的个数(不区分大小写字母),以“000”作为字符串输入结束标志,例如: Twinkletwinklelittlestar000(回车) twinklelittlestar 211(50分) #include #include #include #include voidmain() { charstring[400];//装载输入的原始字符串 chartemp[20][20];//装载string中的各个子字符串 charstr[20][20]; intnum=0;//记录空格的个数 intorder[20];//记录各个空格的位置 inti,j,k; intsum[20]; intflag=0; for(i=0;i<10;i++) memset(temp[i],'\0',20); for(i=0;i<10;i++) memset(str[i],'\0',20); for(i=0;i<10;i++) sum[i]=1; printf("pleaseinputthestring: \n"); gets(string); for(i=0;string[i]! ='0';i++) string[i]=tolower(string[i]);//将字符串中的大写字母转化成小写字母 for(i=0;string[i]! ='0';i++) if(string[i]=='') { order[num]=i;//记录空格的位置 num++;//空格的数目加1 } for(i=0;i temp[0][i]=string[i]; for(j=0;j for(k=0,i=order[j]+1;i temp[j+1][k++]=string[i];//将string字符串分开后存在temp中 for(k=0,i=0;i { flag=0; for(j=0;j if(! strcmp(temp[i],str[j])) { flag=1; break; } if(flag==0) strcpy(str[k++],temp[i]); } for(i=0;i {sum[i]=0; for(j=0;j if(! strcmp(str[i],temp[j])) sum[i]++; printf("%s%d\n",str[i],sum[i]); } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 第五届全国ITAT C语言程序设计A卷答案 第五 全国 ITAT 语言程序设计 答案