西北工业大学-c语言-POJ-题目及答案-第七季

合集下载

西工大2020年4月《C语言程序设计》作业机考参考答案

西工大2020年4月《C语言程序设计》作业机考参考答案

西工大2020年4月《C语言程序设计》作业机考试卷总分:100 得分:96一、单选题(共35 道试题,共70 分)1. 一个C程序的执行是从()。

A.本程序的main函数开始,到main函数结束B.本程序文件的第一个函数开始,到本程序文件的最后一个函数结束C.本程序的main函数开始,到本程序文件的最后一个函数结束D.本程序文件的第一个函数开始,到本程序main函数结束正确答案:A2. 在C语言中,只有在使用时才占用内存单元的变量,其存储类型是()。

A.auto和registerB.extern和registerC.auto和staticD.static和register正确答案:A3. 以下存储类型只有在使用时才为该类型变量分配内存的是()。

A.auto和staticB.auto和registerC.register和staticD.static和extern正确答案:B4. 运行程序:#includemain(){int n='c';switch(n++){ default: printf("error");break;case 'a':case 'A':case 'b':case 'B':printf("good");break;case 'c':case 'C':printf("pass");case 'd':case 'D':printf("warn");}}则输出结果是()。

A.goodB.passC.warnD.passwarn。

西工大C语言大作业习题答案

西工大C语言大作业习题答案

童鞋们,快来呀!答案!答案!no1.绘制余弦曲线在屏幕上用“*”显示0~360度的余弦函数cos(x)曲线*问题分析与算法设计如果在程序中使用数组,这个问题十分简单。

但若规定不能使用数组,问题就变得不容易了。

关键在于余弦曲线在0~360度的区间内,一行中要显示两个点,而对一般的显示器来说,只能按行输出,即:输出第一行信息后,只能向下一行输出,不能再返回到上一行。

为了获得本文要求的图形就必须在一行中一次输出两个“*”。

为了同时得到余弦函数cos(x)图形在一行上的两个点,考虑利用cos(x)的左右对称性。

将屏幕的行方向定义为x,列方向定义为y,则0~180度的图形与180~360度的图形是左右对称的,若定义图形的总宽度为62列,计算出x行0~180度时y点的坐标m,那么在同一行与之对称的180~360度的y点的坐标就应为62-m。

程序中利用反余弦函数acos计算坐标(x,y)的对应关系。

使用这种方法编出的程序短小精炼,体现了一定的技巧。

*程序说明与注释#include<stdio.h>#include<math.h>void main(){double y;int x,m;for(y=1;y>=-1;y-=0.1){m=acos(y)*10;for(x=1;x<m;x++) printf(" ");printf("*");for(;x<62-m;x++)printf(" ");printf("*\\n");}}no2.绘制余弦曲线和直线在屏幕上显示0~360度的cos(x)曲线与直线f(x)=45*(y-1)+31的迭加图形。

其中cos(x)图形用“*”表示,f(x)用“+”表示,在两个图形相交的点上则用f(x)图形的符号。

*问题分析与算法设计本题可以在上题的基础上进行修改。

图形迭加的关键是要在分别计算出同一行中两个图形的列方向点坐标后,正确判断相互的位置关系。

西工大NOJ100题解答

西工大NOJ100题解答

西工大NOJ100题解答#include<tdio.h>intmain(){inta,b,um;canf("%d%d",&a,&b);um=a+b;printf("%d\n",um);return0;}#include<tdio.h>#definePI3.1415926intmain(){doubler,h,l,,q,vq,vz;canf("%lf%lf",&r,&h);l=2某PI某r;=PI 某r某r;q=4某PI某r某r;vq=PI某r某r某r某4/3;vz=PI某r某r 某h;printf("%.2lf\n%.2lf\n%.2lf\n%.2lf\n%.2lf\n",l,,q,vq,vz);ret urn0;}#include<tdio.h>intmain(){doublema,eng,c,um,ave;canf("%lf%lf%lf",&ma,&eng,&c);um=ma+eng+c;ave=um/3;printf("%lf\n%lf\n",um,ave);return0;}#include<tdio.h>intmain(){inta,b,c,m;canf("%d%d%d",&a,&b,&c);if(a>b)m=a;elem=b;if(m<c)m=c;printf( "%d",m);return0;}#include<tdio.h>intmain(){intn;canf("%d",&n);if((1000<n<10000)&&(n/1000==n%10)&&(n/100%10==n/10%10))print f("ye\n");eleif((100<n<=1000)&&(n/100==n%10))printf("ye\n");elei f((10<n<=100)&&(n/10==n%10))printf("ye\n");eleif(0<n<=10)printf( "ye\n");eleprintf("no\n");return0;}#include<tdio.h>intmain(){doublel,bon;canf("%lf",&l);if(l<=10)bon=l某0.1;eleif(l<20)bon=1+(l-10)某0.075;eleif(l<40)bon=1.75+(l-20)某0.05;eleif(l<60)bon=2.75+(l-40)某0.03;eleif(l<100)bon=3.35+(l-60)某0.015;elebon=3.95+(l-100)某0.01;printf("%lf\n",bon);return0;}#include<tdio.h>intmain(){doubled,m;canf("%lf",&d);if(d<=2)m=7;eleif(d<=15){if(d-2==(int)(d-2))m=7+(d-2)某1.5;elem=7+((int)(d-2)+1)某1.5;}eleif(d-15==(int)(d-15))m=26.5+(d-15)某2.1;elem=26.5+((int)(d-15)+1)某2.1;printf("%lf\n",m);return0;}#include<tdio.h>intmain(){inty,m,d,Day,um;canf("%d-%d-%d",&y,&m,&d);if((y%4==0&&y%100!=0)||(y%400==0))Day=29;eleDay=28;witch(m){ cae1:um=d;break;cae2:um=31+d;break;cae3:um=31+Day+d;break;cae4:um=62+Day+d;break;cae5:um=92+Day +d;break;cae6:um=123+Day+d;break;cae7:um=153+Day+d;break;cae8:um =184+Day+d;break;cae9:um=215+Day+d;break;cae10:um=245+Day+d;brea k;cae11:um=276+Day+d;break;cae12:um=307+Day+d;break;} printf("%d\n",um);return0;}#include<tdio.h>intmain(){inti;canf("%d",&i);if(i>=90)printf("A\n");eleif(i>=80)printf("B\n");eleif(i>=70)printf("C\n");eleif(i> =60)printf("D\n");eleprintf("E\n");return0;}#include<tdio.h>intmain(){double某,y;canf("%lf,%lf",&某,&y);if((某-2)某(某-2)+(y-2)某(y-2)<=1)printf("10");eleif((某-2)某(某-2)+(y+2)某(y+2)<=1)printf("10");eleif((某+2)某(某+2)+(y-2)某(y-2)<=1)printf("10");eleif((某+2)某(某+2)+(y+2)某(y+2)<=1)printf("10");eleprintf("0");return0;}doublel,某,r;canf("%lf%lf",&l,&r);while((2某l某l某l-4某l某l+3某l-6)!=0&&(2某r某r某r-4某r某r+3某r-6)!=0){某=(l+r)/2;if((2某l某l某l-4某l某l+3某l-6)某(2某某某某某某-4某某某某+3某某-6)<=0)r=某;elel=某;}if(2某l某l某l-4某l某l+3某l-6==0)printf("%.2lf",l);eleprintf("%.2lf",r);return0;} #include<tdio.h>#include<math.h>intmain(){inti=800,t=2,cnt=0,um=0;doublee=-1;while(i>=500){while(t<=i-1){if(i%t==0)break;t++;}if(t==i)e=pow(-1,cnt),um=um+e某i,cnt++;i--;t=2;}printf("%d%d",cnt,um);return0;}#include<tdio.h>#include<math.h>intmain(){inta=1;doubleb=1,pi=0,c=1;while(fab(c)>=1e-6)pi=pi+c,b=b+2,a=-a,c=a/b;pi=pi某4;printf("%lf\n",pi);return0;}inta1=1,a2=1,n=2,um=2,t;while(um<=100){t=a1;a1=a2; a2=t+2某a2;um=um+a2;n++;}printf("%d\n",n-1);while(um<=1000){t=a1;a1=a2;a2=t+2某a2;um=um+a2;n++;}printf("%d\n",n-1);while(um<=10000){t=a1;a1=a2;a2=t+2某a2;um=um+a2;n++;}printf("%d\n",n-1);}#include<tdio.h>intmain(){int某,a,,n=1;canf("%d%d",&某,&a);=某;if(a!=0){for(;n<a;n++){=某某;if(>=1000)=/100%10某100+/10%10某10+%10;}}printf("%d\n",);return0;}#include<tdio.h>intmain(){intm,n,;canf("%d",&n);=n某n某n;printf("%d某%d某%d=%d=",n,n,n,);for(m=1;!=n某m;m++);if(n%2==1){for(=-n/2;<n/2;++)printf("%d+",m+2某);printf("%d",m+n/2某2);}ele{for(=-n/2;<n/2-1;++)printf("%d+",m+某2+1);printf("%d",m+(n/2-1)某2+1);}return0;}#include<tdio.h>intmain(){chara,b,c,某,y,z;a='A',b='B',c='C',某='某',y='Y',z='Z';printf("%c=%c\n",a,z);printf("%c=%c\n",b,某);printf("%c=%c\n",c,y);return0;}#include<tdio.h>intmain(){inta,b,t;canf("%d%d",&a,&b);if(a>b)t=a,a=b,b=t;for(;a<b;a++){for(t=2;t<a;t++)if(a%t==0)break;if(t==a)printf("%d",a);} return0;}#include<tdio.h>intmain(){intn=1;doublea1=1,a2=2,a3,um=2;while(n<=19){a3=a1+a2;um=um+a3/a2;a1=a2;a2=a3;n++;}printf("%lf\n",um);return0;}#include<tdio.h>#include<math.h>intmain(){ doublea;intn=0;canf("%lf",&a);a=fab(a);if(a<=1)printf("0\n");ele{while(a>1){a=a/10;n++;}printf("%d\n",n);}return0;}#include<tdio.h>intmain(){inta=1,b=0,t,m,n=0;canf("%d",&t);while(n<t){m=b; b=3某a+2某b;a=m;n++;}printf("%d%d",a,b);return0;}。

机械原理第七版西北工业大学课后习题答(8-11章)整本是的重点

机械原理第七版西北工业大学课后习题答(8-11章)整本是的重点

第8章课后习题参考答案8-l 铰链四杆机构中,转动副成为周转副的条件是什么?在下图所示四杆机构ABCD 中哪些运动副为周转副?当其杆AB 与AD 重合时,该机构在运动上有何特点?并用作图法求出杆3上E 点的连杆曲线。

答:转动副成为周转副的条件是:(1)最短杆与最长杆的长度之和小于或等于其他两杆长度之和;(2)机构中最短杆上的两个转动副均为周转副。

图示ABCD 四杆机构中C 、D 为周转副。

当其杆AB 与AD 重合时,杆BE 与CD 也重合因此机构处于死点位置。

8-2曲柄摇杆机构中,当以曲柄为原动件时,机构是否一定存在急回运动,且一定无死点?为什么? 答:机构不一定存在急回运动,但一定无死点,因为:(1)当极位夹角等于零时,就不存在急回运动如图所示,(2)原动件能做连续回转运动,所以一定无死点。

8-3 四杆机构中的极位和死点有何异同?8-4图a 为偏心轮式容积泵;图b 为由四个四杆机构组成的转动翼板式容积泵。

试绘出两种泵的机构运动简图,并说明它们为何种四杆机构,为什么?解 机构运动简图如右图所示,ABCD 是双曲柄机构。

因为主动圆盘AB 绕固定轴A 作整周转动,而各翼板CD 绕固定轴D 转动,所以A 、D 为周转副,杆AB 、CD 都是曲柄。

8-5试画出图示两种机构的机构运动简图,并说明它们各为何种机构。

图a 曲柄摇杆机构图b 为导杆机构。

8-6如图所示,设己知四杆机构各构件的长度为240a mm =,600b =mm ,400,500c mm d mm ==。

试问:1)当取杆4为机架时,是否有曲柄存在?2)若各杆长度不变,能否以选不同杆为机架的办法获得双曲柄机构和双摇杆机构?如何获得?3)若a 、b ﹑c 三杆的长度不变,取杆4为机架,要获得曲柄摇杆机构,d 的取值范围为何值? :解 (1)因a+b=240+600=840≤900=400+500=c+d 且最短杆 1为连架轩.故当取杆4为机架时,有曲柄存在。

西北工业大学2020春机考《C语言程序设计》答案 -

西北工业大学2020春机考《C语言程序设计》答案 -

西北工业大学2020春机考《C语言程序设计》作业1单选题1.下面程序的输出结果是()。

main() { int a[10]={1,2,3,4,5,6,7,8,9,10,*p=a;A.3B.4C.1D.2答案:VX:34637870获取参考答案2.以下描述错误的是()。

A.break 语句不能用于循环语句和 switch 语句外的任何其他语句B.在 switch 语句中使用 break 语句或 continue 语句的作用相同C.在循环语句中使用 continue 语句是为了结束本次循环,而不是终止整个循环D.在循环语句中使用 break 语句是为了使流程跳出循环体,提前结束循环答案:VX:34637870获取参考答案3.下面程序的输出结果是()。

main() { int x=10; x+=(x=8); printf("%d\n",x); }A.10B.8C.18D.16答案:VX:34637870获取参考答案4.定义 int i=1; 则执行语句 while(i++<5); 后,i 的值为()。

A.3B.4C.5D.6答案:VX:34637870获取参考答案5.若有语句 scanf("%d%d",&a,&b);要使变量 a,b 分别得到 10 和 20,正确的输入形式为()。

A.10 20B.10,20C.1020D.10:20答案:VX:34637870获取参考答案6.有以下定义 #include char a[10],*b=a; 不能给 a 数组输入字符串的语句是()。

A.gets(a)B.gets(a[0]);C.gets(&a[0]);D.gets(b)答案:VX:34637870获取参考答案7.当 c 的值不为 0 时,在下列选项中能够将 c 的值赋给变量 a、b 的是()。

A.c=b=a;B.(a=c)||(b=c);C.(a=c)&&(b=c);答案:VX:34637870获取参考答案8.以下描述中正确的是()。

西工大noj标准答案版.doc

西工大noj标准答案版.doc

西北工业大学 POJ答案绝对是史上最全版(不止100哦⋯⋯按首字母排序)1.“ 1“的传奇2.A+B3.A+BⅡ4.AB5.ACKERMAN6.Arithmetic Progressions7.Bee8.Checksum algorithm9.Coin Test10.Dexter need help11.Double12.Easy problem13.Favorite number14.Graveyard15.Hailstone16.HanoiⅡ17.Houseboat18.Music Composer19.Redistribute wealth20.Road trip21.Scoring22.Specialized Numbers23.Sticks24.Sum of Consecutive25.Symmetric Sort26.The Clock27.The Ratio of gainers to losers28.VOL 大学乒乓球比赛29.毕业设计论文打印30.边沿与内芯的差31.不会吧,又是 A+B32.不屈的小蜗33.操场训练34.插入链表节点35.插入排序36.插入字符37.成绩表计算38.成绩转换39.出租车费40.除法41.创建与遍历职工链表42.大数乘法43.大数除法44.大数加法45.单词频次46.迭代求根47.多项式的猜想48.二分查找49.二分求根50.发工资的日子51.方差52.分离单词53.分数拆分54.分数化小数55.分数加减法56.复数57.高低交换58.公园喷水器59.韩信点兵60.行程编码压缩算法61.合并字符串62.猴子分桃63.火车站64.获取指定二进制位65.积分计算66.级数和67.计算 A+B68.计算 PI69.计算π70.计算成绩71.计算完全数72.检测位图长宽73.检查图像文件格式74.奖金发放75.阶乘合计76.解不等式77.精确幂乘78.恐怖水母79.快速排序80.粒子裂变81.链表动态增长或缩短82.链表节点删除83.两个整数之间所有的素数84.路痴85.冒泡排序86.你会存钱吗87.逆序整数88.排列89.排列分析90.平均值函数91.奇特的分数数列92.求建筑高度93.区间内素数94.三点顺序95.山迪的麻烦96.删除字符97.是该年的第几天98.是该年的第几天99.数据加密100.搜索字符101.所有素数102.探索合数世纪103.特殊要求的字符串104.特殊整数105.完全数106.王的对抗107.危险的组合108.文件比较109.文章统计110.五猴分桃111.小型数据库112.幸运儿113.幸运数字” 7“114.选择排序115.寻找规律116.循环移位117.延伸的卡片118.羊羊聚会119.一维数组”赋值“120.一维数组”加法“121.勇闯天涯122.右上角123.右下角124.圆及圆球等的相关计算125.圆及圆球等相关计算126.程序员添加行号127.找出数字128.找幸运数129.找最大数130.整数位数131.重组字符串132.子序列的和133.子字符串替换134.自然数立方的乐趣135.字符串比较136.字符串复制137.字符串加密编码138.字符串逆序139.字符串排序140.字符串替换141.字符串左中右142.组合数143.最次方数144.最大乘积145.最大整数146.最小整数147.最长回文子串148.左上角149.左下角1.“ 1“的传奇#include <>#include <>#include <>int main(){int n,i,j,k=0,x=1,y,z,m,p,q,a,s=0;scanf("%d",&n);m=n;for(i=1;i<12;i++){m=m/10;k++;if(m==0)break;}q=n;k=k-1;for(a=1;a<=k;a++){x=x*10;}y=q%x;z=q/x;p=q-y;if(z>=2)s=s+x+z*k*(x/10); elses=s+z*k*(x/10); for(j=p;j<=n;j++) {m=j;for(i=1;i<12;i++){x=m%10;if(x==1)s++;m=m/10;if(m==0)break;}}printf("%d",s);return 0;}2.A+B#include <>int doubi(int n,int m) {n=n+m;n=n%100;return n;}int main(){int t,i,a[100],n,m; scanf("%d",&t);for (i=0;i<=(t-1);i++){scanf("%d%d",&n,&m);a[i]=doubi(n,m);}for (i=0;i<=(t-1);i++)printf("%d\n",a[i]); return 0;}3.A+BⅡ#include <>int main(){int A,B,sum;scanf("%d%d",&A,&B);sum=A+B;printf("%d\n",sum);return 0;}4.AB#include <>#include <>#include <>int main(){char s[100],q[100];double a,b,c;int n=0,i;scanf("%lf%lf",&a,&b);c=a*b;sprintf(s,"%.0lf",c);for(i=0;i<strlen(s);i++){n=n+s[i]-48;}while(n>=10){sprintf(q,"%d",n);n=0;for(i=0;i<strlen(q);i++)n=n+q[i]-48;}printf("%d",n);return 0;}5.ACKERMAN#include <>#include <>int ack(int x,int y){int n;if (x==0) {n=y+1;return n;}else if (y==0) n=ack(x-1,1);else n=ack(x-1,ack(x,y-1));return n;}int main(){int m,b;scanf("%d%d",&m,&b);m=ack(m,b);printf("%d",m);return 0;}6.Arithmetic Progressions #include <>#include <>int g(int n){int i;if(n==1) return 0;if(n==2) return 1;if(n==3) return 1;for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0;return 1;}int f(int a,int b,int c){int i=0,s=a-b;if(c==1&&g(a)==1) return a;if(b==0&&g(a)!=1) return -1;while(1){s=s+b;if(g(s)) i++;if(i>=c) break;}return s;int main(){int a,b,c,d[100],i=0,n;while(1){scanf("%d%d%d",&a,&b,&c);if(a==0&&b==0&&c==0) break;d[i]=f(a,b,c);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",d[i]);return 0;}7.Bee#include <>#include <>int main()int A[100],i=0,j,k,female=0,male=1,x;for(;;i++){scanf("%d",&A[i]);if(A[i]==-1)break;}for(j=0;j<i;j++){female=0,male=1;for(k=1;k<A[j];k++){x=female;female=male;male=x+male+1;}printf("%d %d\n",male,female+male+1);}return 0;}8.Checksum algorithm #include <>#include <>#include <>int main(){int i,n,t,j;char s[100][100];for(i=0;;i++){gets(s[i]);if(s[i][0]=='#') break;}n=i;for(i=0;i<n;i++){t=0;for(j=0;j<strlen(s[i]);j++)if(s[i][j]==32) t=t;else t=t+(j+1)*(s[i][j]-64);printf("%d\n",t);}return 0;}9.Coin Test#include <>#include <>int main(){char A[100000];int n,i=0,a=0,b=0,j;double x;while(1){scanf("%c",&A[i]);if(A[i]=='\n')break;i++;}for(j=0;j<i;j++){if(A[j]=='S'){printf("WA");goto OH;}if(A[j]=='U')a++;if(A[j]=='D')b++;}x=a*(a+b)*;if>||<printf("Fail");elseprintf("%d/%d",a,a+b);OH:return 0;}10.Dexter need help #include <>int fun(int a){if(a==1) return 1;elsereturn fun(a/2)+1; }int main(){int a,b[100],i=0,j; while(1){scanf("%d",&a);if(a==0)break;b[i]=fun(a);i++;}for(j=0;j<i;j++){ printf("%d\n",b[j]); }return 0;}11.Double#include <>#include <>int main(){int a[100],b[100],i,j,n,t=0;for(i=0;;i++){scanf("%d",&a[i]);if(a[i]==0) break;}n=i;for(i=0;i<n;i++)b[i]=2*a[i];for(i=0;i<n;i++)for(j=0;j<n;j++)if(a[i]==b[j]) t++;printf("%d",t);return 0;}12.Easy problem#include <>#include <>int main(){int N,i,n,j=0;scanf("%d",&N);for(i=2;i<N+1;i++){if((N+1)%i==0)j++;}printf("%d",j/2);return 0;}13.Favorite number #include <>#include <>#define MAXNUM 100000int prime_number = 0;int prime_list[MAXNUM]; bool is_prime[MAXNUM]; int ans[MAXNUM + 2];int dp[MAXNUM + 2];void set_prime() {int i, j;memset(is_prime, 0, sizeof(is_prime));for (i = 2; i < MAXNUM; i++) {if (is_prime[i] == 0) {prime_list[prime_number++] = i;if (i >= MAXNUM / i) continue;for (j = i * i; j < MAXNUM; j+=i) {is_prime[j] = 1;}}}}int main() {int i, j, k,o=0,d[100];memset(dp, -1, sizeof(dp));set_prime();ans[0] = 0;dp[1] = 0;for (i = 1; i <= MAXNUM; i++) {ans[i] = ans[i - 1] + dp[i];if (dp[i + 1] == -1 || dp[i + 1] > dp[i] + 1) {dp[i + 1] = dp[i] + 1;}for (j = 0; j < prime_number; j++) {if (i > MAXNUM / prime_list[j]) break;k = i * prime_list[j];if (dp[k] == -1 || dp[k] > dp[i] + 1) {dp[k] = dp[i] + 1;}}}while (scanf("%d%d", &i, &j) == 2 && (i || j)){ d[o]=ans[j] - ans[i - 1];o++;}for(i=0;i<o;i++)printf("%d\n",d[i]);}14.Graveyard#include <>#include <>#include <>int main(){int a[100],b[100],n,i,j;double s,p,l,t;for(i=0;;i++){scanf("%d%d",&a[i],&b[i]);if(a[i]==0&&b[i]==0) break;}n=i;for(i=0;i<n;i++){p=10000;if(b[i]%a[i]==0){printf("\n");continue;};t=10000/((double)a[i]);for(j=1;j<a[i]+b[i];j++){l=10000/((double)(a[i]+b[i]));l=t-j*l;l=fabs(l);if(l<p) p=l;}s=(a[i]-1)*p;printf("%.4lf\n",s);}return 0;}15.Hailstone#include <>#include <>#include <>int f(int n){int s=1;while(1){if(n==1) return s;else if(n%2==0) n=n/2,s++;else n=3*n+1,s++;}}int main(){int n,m,i,j=0,t;scanf("%d%d",&m,&n);printf("%d %d",m,n);if(m>n) t=m,m=n,n=t;for(i=m;i<=n;i++)if(f(i)>j) j=f(i);printf(" %d",j);return 0;}16.HanoiⅡ#include <>#include <>#define M 70int start[M], targe[M];long long f(int *p, int k, int fina) {if(k==0) return 0;if(p[k]==fina) return f(p,k-1,fina);return f(p,k-1,6-fina-p[k])+(1LL<<(k-1));}int main (){long long ans;int n;while(scanf("%d",&n),n){int i;for(i=1;i<=n;i++) scanf("%d",&start[i]);for(i=1;i<=n;i++) scanf("%d",&targe[i]);int c=n;for(;c>=1&&start[c]==targe[c];c--);if(c==0){printf("0\n"); continue;}int other=6-start[c]-targe[c]; ans=f(start,c-1,other)+f(targe,c-1,other)+1;printf("%lld\n",ans);}return 0;}17.Houseboat#include <>#include <>#include <>#define piint f(float x,float y){int i;for(i=0;;i++)if(50*i>sqrt(x*x+y*y)*sqrt(x*x+y*y)*pi/2) break;return i;}int main(){int n,i,a[100];float x,y;scanf("%d",&n);for(i=0;i<n;i++){scanf("%f%f",&x,&y);a[i]=f(x,y);}for(i=0;i<n;i++)printf("%d %d\n",i+1,a[i]);return 0;}18.Music Composer19.Redistribute wealth#include <>#include <>#include <>int main(){inta[1000],b[1000],n,i,j,s,sum,t,m,mid,c[100],k=0;while(1){scanf("%d",&n);if(n==0) break;{s=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);s=s+a[i];}m=s/n;b[1]=a[1]-m;b[0]=0;for(i=2;i<n;++i)b[i]=b[i-1]+a[i]-m;for(i=0;i<n;i++)for(j=0;j<n-1-i;j++)if(b[j]>b[j+1])t=b[j],b[j]=b[j+1],b[j+1]=t;mid=b[n/2];sum=0;for(i=0;i<=n-1;++i) sum=sum+fabs(mid-b[i]);c[k]=sum;k++;}}for(i=0;i<k;i++) printf("%d\n",c[i]);return 0;}20.Road trip#include <>#include <>#include <>int f(int n){int a[100],b[100],i,s;for(i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);s=a[0]*b[0];for(i=1;i<n;i++)s=s+a[i]*(b[i]-b[i-1]);return s;}int main(){int n,c[100],i=0;while(1){scanf("%d",&n);if(n==-1) break;c[i]=f(n);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",c[i]);return 0;}21.Scoring#include <>#include <>#include <>int main(){int i,j,sum,min,c,count,n,a,b; char s1[50],s2[50];scanf("%d",&n);for(i=0;i<n;i++){count=sum=0;scanf("%s",s2);for(j=0;j<4;j++){scanf("%d%d",&a,&b);if(b!=0){sum+=(a-1)*20+b;count++;}}if(i==0){c=count,min=sum;strcpy(s1,s2);}else if(count>c||(count==c&&sum<min)) {min=sum;c=count;strcpy(s1,s2);}}printf("%s %d %d\n",s1,c,min); return 0;}22.Specialized Numbers#include <>#include <>int main(){int i,n,sum10,sum12,sum16;for(i=2992;i<3000;i++){n=i;sum10=0;while(n){sum10+=n%10;n/=10;}n=i;sum12=0;while(n){sum12+=n%12;n/=12;}n=i;sum16=0;while(n){sum16+=n%16;n/=16;}if(sum10==sum12&&sum12==sum16) printf("%d\n",i);}return 0;}23.Sticks#include <>#include <>#include <>int len[64], n, minlen, get;bool b[64];int cmp(const void *a, const void *b) {return *(int *)a < *(int *)b 1 : -1;}bool dfs(int nowlen, int nowget, int cnt) {if(cnt >= n) return false;if(get == nowget) return true;int i;bool f = false;if(nowlen == 0) f = true;for(i = cnt; i < n; i++){if(!b[i]){if(len[i] + nowlen == minlen){b[i] = true;if(dfs(0, nowget+1, nowget))return true;b[i] = false;return false;}else if(len[i] + nowlen < minlen){b[i] = true;if(dfs(nowlen+len[i], nowget, i+1))return true;b[i] = false;if(f) return false;while(i+ 1 < n && len[i] == len[i+1]) i++;}}}return false;}int main(){int i, tollen;while(scanf("%d", &n), n){tollen = 0;int j = 0, p;for(i = 0; i < n; i++){scanf("%d", &p);if(p <= 50){len[j] = p;tollen += len[j];j++;}}n = j;if(n == 0){printf("0\n");continue;}qsort(len, n, sizeof(int), cmp); for(minlen = len[0]; ; minlen++) {if(tollen % minlen) continue;memset(b, 0, sizeof(b));get = tollen / minlen;if(dfs(0, 0, 0)){printf("%d\n", minlen);break;}}}return 0;}24.Sum of Consecutive#include <>#include <>#include <>int len[64],n,minlen,get;int b[64];int cmp(const void *a,const void *b) {return *(int *)a<*(int *)b1:-1;}int dfs(int nowlen,int nowget,int cnt){if(cnt>=n) return 0;if(get==nowget) return 1;int i,f=0;if(nowlen==0) f=1;for(i=cnt;i<n;i++){if(len[i]+nowlen==minlen){b[i]=1;if(dfs(0,nowget+1,nowget)) return 1;b[i]=0;return 0;}else if(len[i]+nowlen<minlen){b[i]=1;if(dfs(nowlen+len[i],nowget,i+1)) return 1;b[i]=0;if(f) return 0;while(i+1<n&&len[i]==len[i+1]) i++;}}return 0;}int main(){int i,tollen,q=0,c[100];while(scanf("%d",&n),n){tollen=0;int j=0,p;for(i=0;i<n;i++){scanf("%d",&p);if(p<=50){len[j]=p;tollen+=len[j];j++;}}n=j;if(n==0){printf("0\n");continue;}qsort(len,n,sizeof(int),cmp);for(minlen=len[0];;minlen++){if(tollen%minlen) continue;memset(b,0,sizeof(b));get=tollen/minlen;if(dfs(0,0,0)){c[q]=minlen;q++;break;}}}for(i=0;i<q;i++)printf("%d\n",c[i]);return 0;}25.Symmetric Sort#include <>#include <>#include <>int main(){double A[100];int i=0,j=0,k=0,l=0,sum=0;while(1){scanf("%lf",&A[i]);if(A[i]==0)break;i++;}for(j=0;j<i;j++){if(A[j]==2)printf("1\n");else{int B[10000],m=1,number=0;double n;B[0]=2;for(k=3;k<=A[j];k+=2){n=(double)k;for(l=2;l<=sqrt(n);l++){if(k%l==0)goto ai;}B[m]=k;m++;ai:;}for(k=0;k<m;k++){sum=0;for(l=k;l<m;l++){sum+=B[l];if(sum==A[j]){number++;break;}}}printf("%d\n",number);}}return 0;}26.The Clock#include <>#include <>#include <>int main(){char s[100][100],a[100];int i,j,n;scanf("%d",&n);for(i=0;i<n;i++) scanf("%s",s[i]);for(i=0;i<n-1;i++)for(j=0;j<n-1-i;j++)if(strlen(s[i])>strlen(s[i+1]))strcpy(a,s[i]),strcpy(s[i],s[i+1]),strcpy(s[i+1],a) ;if(n%2==0){for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-3;i>0;i=i-2) printf("%s ",s[i]);}else{for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-1;i>0;i=i-2) printf("%s ",s[i]);}return 0;}27.The Ratio of gainers to losers #include<>int main(){char s[5];int i,sum=0;gets(s);for(i=0;s[i]!='\0';i++){switch(s[i]){case'I': sum+=1;break; case'V': sum=5-sum;break; case'X':sum=10-sum;break; }}printf("%d\n",sum);return 0;}28.VOL大学乒乓球比赛#include <>#include <>int main(){printf("A=Z\nB=X\nC=Y\n");return 0;}29.毕业设计论文打印#include <>#include <>int main(){int a[100],j=1,i,n,m;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)if(a[i]>a[m]) j++;printf("%d",j++);return 0;}30.边沿与内芯的差#include <>#include <>int main(){int A[100][100],i,j,m,n,s=0,t=0;scanf("%d%d",&n,&m);for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&A[i][j]);}。

西工大noj问题详解解析汇报(完整版)

西工大noj问题详解解析汇报(完整版)

西北工业大学POJ答案绝对是史上最全版(不止100题哦……按首字母排序)1.“1“的传奇2.A+B3.A+BⅡ4.AB5.ACKERMAN6.Arithmetic Progressions7.Bee8.Checksum algorithm9.Coin Test10.Dexter need help11.Double12.Easy problem13.Favorite number14.Graveyard15.Hailstone16.Hanoi Ⅱ17.Houseboat18.Music Composer19.Redistribute wealth20.Road trip21.Scoring22.Specialized Numbers23.Sticks24.Sum of Consecutive25.Symmetric Sort26.The Clock27.The Ratio of gainers to losers28.VOL大学乒乓球比赛29.毕业设计论文打印30.边沿与内芯的差31.不会吧,又是A+B32.不屈的小蜗33.操场训练34.插入链表节点35.插入排序36.插入字符37.成绩表计算38.成绩转换39.出租车费40.除法41.创建与遍历职工链表42.大数乘法43.大数除法44.大数加法45.单词频次46.迭代求根47.多项式的猜想48.二分查找49.二分求根50.发工资的日子51.方差52.分离单词53.分数拆分54.分数化小数55.分数加减法56.复数57.高低交换58.公园喷水器59.韩信点兵60.行程编码压缩算法61.合并字符串62.猴子分桃63.火车站64.获取指定二进制位65.积分计算66.级数和67.计算A+B68.计算PI69.计算π70.计算成绩71.计算完全数72.检测位图长宽73.检查图像文件格式74.奖金发放75.阶乘合计76.解不等式77.精确幂乘78.恐怖水母79.快速排序80.粒子裂变81.链表动态增长或缩短82.链表节点删除83.两个整数之间所有的素数84.路痴85.冒泡排序86.你会存钱吗87.逆序整数88.排列89.排列分析90.平均值函数91.奇特的分数数列92.求建筑高度93.区间内素数94.三点顺序95.山迪的麻烦96.删除字符97.是该年的第几天98.是该年的第几天?99.数据加密100.搜索字符101.所有素数102.探索合数世纪103.特殊要求的字符串104.特殊整数105.完全数106.王的对抗107.危险的组合108.文件比较109.文章统计110.五猴分桃111.小型数据库112.幸运儿113.幸运数字”7“114.选择排序115.寻找规律116.循环移位117.延伸的卡片118.羊羊聚会119.一维数组”赋值“120.一维数组”加法“121.勇闯天涯122.右上角123.右下角124.圆及圆球等的相关计算125.圆及圆球等相关计算126.程序员添加行号127.找出数字128.找幸运数129.找最大数130.整数位数131.重组字符串132.子序列的和133.子字符串替换134.自然数立方的乐趣135.字符串比较136.字符串复制137.字符串加密编码138.字符串逆序139.字符串排序140.字符串替换141.字符串左中右142.组合数143.最次方数144.最大乘积145.最大整数146.最小整数147.最长回文子串148.左上角149.左下角1.“1“的传奇#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int n,i,j,k=0,x=1,y,z,m,p,q,a,s=0;scanf("%d",&n);m=n;for(i=1;i<12;i++){m=m/10;k++;if(m==0)break;}q=n;k=k-1;for(a=1;a<=k;a++){x=x*10;}y=q%x;z=q/x;p=q-y;if(z>=2)s=s+x+z*k*(x/10); elses=s+z*k*(x/10); for(j=p;j<=n;j++) {m=j;for(i=1;i<12;i++){x=m%10;if(x==1)s++;m=m/10;if(m==0)break;}}printf("%d",s);return 0;}2.A+B#include <stdio.h>int doubi(int n,int m){n=n+m;n=n%100;return n;}int main(){int t,i,a[100],n,m;scanf("%d",&t);for (i=0;i<=(t-1);i++){scanf("%d%d",&n,&m);a[i]=doubi(n,m);}for (i=0;i<=(t-1);i++)printf("%d\n",a[i]);return 0;}3.A+BⅡ#include <stdio.h>int main(){int A,B,sum;scanf("%d%d",&A,&B);sum=A+B;printf("%d\n",sum);return 0;}4.AB#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){char s[100],q[100];double a,b,c;int n=0,i;scanf("%lf%lf",&a,&b);c=a*b;sprintf(s,"%.0lf",c);for(i=0;i<strlen(s);i++){n=n+s[i]-48;}while(n>=10){sprintf(q,"%d",n);n=0;for(i=0;i<strlen(q);i++)n=n+q[i]-48;}printf("%d",n);return 0;}5.ACKERMAN#include <stdio.h>#include <stdlib.h>int ack(int x,int y){int n;if (x==0) {n=y+1;return n;}else if (y==0) n=ack(x-1,1);else n=ack(x-1,ack(x,y-1));return n;}int main(){int m,b;scanf("%d%d",&m,&b);m=ack(m,b);printf("%d",m);return 0;}6.Arithmetic Progressions#include <stdio.h>#include <math.h>int g(int n){int i;if(n==1) return 0;if(n==2) return 1;if(n==3) return 1;for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0;return 1;}int f(int a,int b,int c){int i=0,s=a-b;if(c==1&&g(a)==1) return a;if(b==0&&g(a)!=1) return -1;while(1){s=s+b;if(g(s)) i++;if(i>=c) break;}return s;int main(){int a,b,c,d[100],i=0,n;while(1){scanf("%d%d%d",&a,&b,&c);if(a==0&&b==0&&c==0) break;d[i]=f(a,b,c);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",d[i]);return 0;}7.Bee#include <stdio.h>#include <stdlib.h>int main()int A[100],i=0,j,k,female=0,male=1,x;for(;;i++){scanf("%d",&A[i]);if(A[i]==-1)break;}for(j=0;j<i;j++){female=0,male=1;for(k=1;k<A[j];k++){x=female;female=male;male=x+male+1;}printf("%d %d\n",male,female+male+1);}return 0;}8.Checksum algorithm#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,n,t,j;char s[100][100];for(i=0;;i++){gets(s[i]);if(s[i][0]=='#') break;}n=i;for(i=0;i<n;i++){t=0;for(j=0;j<strlen(s[i]);j++)if(s[i][j]==32) t=t;else t=t+(j+1)*(s[i][j]-64);printf("%d\n",t);}return 0;}9.Coin Test#include <stdio.h>#include <stdlib.h>int main(){char A[100000];int n,i=0,a=0,b=0,j;double x;while(1){scanf("%c",&A[i]);if(A[i]=='\n')break;i++;}for(j=0;j<i;j++){if(A[j]=='S'){printf("WA");goto OH;}if(A[j]=='U')a++;if(A[j]=='D')b++;}x=a*1.0/(a+b)*1.0;if(x-0.5>0.003||x-0.5<-0.003) printf("Fail");elseprintf("%d/%d",a,a+b);OH:return 0;}10.Dexter need help#include <stdio.h>int fun(int a){if(a==1) return 1;elsereturn fun(a/2)+1;}int main(){int a,b[100],i=0,j; while(1){scanf("%d",&a);if(a==0)break;b[i]=fun(a);i++;}for(j=0;j<i;j++){printf("%d\n",b[j]); }return 0;}11.Double#include <stdio.h>#include <stdlib.h>int main(){int a[100],b[100],i,j,n,t=0;for(i=0;;i++){scanf("%d",&a[i]);if(a[i]==0) break;}n=i;for(i=0;i<n;i++)b[i]=2*a[i];for(i=0;i<n;i++)for(j=0;j<n;j++)if(a[i]==b[j]) t++;printf("%d",t);return 0;}12.Easy problem#include <stdio.h>#include <math.h>int main(){int N,i,n,j=0;scanf("%d",&N);for(i=2;i<N+1;i++){if((N+1)%i==0)j++;}printf("%d",j/2);return 0;}13.Favorite number #include <stdio.h>#include <string.h>#define MAXNUM 100000int prime_number = 0;int prime_list[MAXNUM]; bool is_prime[MAXNUM]; int ans[MAXNUM + 2];int dp[MAXNUM + 2];void set_prime() {int i, j;memset(is_prime, 0, sizeof(is_prime));for (i = 2; i < MAXNUM; i++) {if (is_prime[i] == 0) {prime_list[prime_number++] = i;if (i >= MAXNUM / i) continue;for (j = i * i; j < MAXNUM; j+=i) {is_prime[j] = 1;}}}}int main() {int i, j, k,o=0,d[100];memset(dp, -1, sizeof(dp));set_prime();ans[0] = 0;dp[1] = 0;for (i = 1; i <= MAXNUM; i++) {ans[i] = ans[i - 1] + dp[i];if (dp[i + 1] == -1 || dp[i + 1] > dp[i] + 1) {dp[i + 1] = dp[i] + 1;}for (j = 0; j < prime_number; j++) {if (i > MAXNUM / prime_list[j]) break;k = i * prime_list[j];if (dp[k] == -1 || dp[k] > dp[i] + 1) {dp[k] = dp[i] + 1;}}}while (scanf("%d%d", &i, &j) == 2 && (i || j)) { d[o]=ans[j] - ans[i - 1];o++;}for(i=0;i<o;i++)printf("%d\n",d[i]);}14.Graveyard#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int a[100],b[100],n,i,j;double s,p,l,t;for(i=0;;i++){scanf("%d%d",&a[i],&b[i]);if(a[i]==0&&b[i]==0) break;}n=i;for(i=0;i<n;i++){p=10000;if(b[i]%a[i]==0){printf("0.0000\n");continue;};t=10000/((double)a[i]);for(j=1;j<a[i]+b[i];j++){l=10000/((double)(a[i]+b[i]));l=t-j*l;l=fabs(l);if(l<p) p=l;}s=(a[i]-1)*p;printf("%.4lf\n",s);}return 0;}15.Hailstone#include <stdio.h>#include <stdlib.h>#include <string.h>int f(int n){int s=1;while(1){if(n==1) return s;else if(n%2==0) n=n/2,s++;else n=3*n+1,s++;}}int main()int n,m,i,j=0,t;scanf("%d%d",&m,&n);printf("%d %d",m,n);if(m>n) t=m,m=n,n=t;for(i=m;i<=n;i++)if(f(i)>j) j=f(i);printf(" %d",j);return 0;}16.Hanoi Ⅱ#include <stdio.h>#include <stdlib.h>#define M 70int start[M], targe[M];long long f(int *p, int k, int fina){if(k==0) return 0;if(p[k]==fina) return f(p,k-1,fina); return f(p,k-1,6-fina-p[k])+(1LL<<(k-1));int main (){long long ans;int n;while(scanf("%d",&n),n){int i;for(i=1;i<=n;i++) scanf("%d",&start[i]);for(i=1;i<=n;i++) scanf("%d",&targe[i]);int c=n;for(;c>=1&&start[c]==targe[c];c--);if(c==0){printf("0\n"); continue;}int other=6-start[c]-targe[c];ans=f(start,c-1,other)+f(targe,c-1,other)+1;printf("%lld\n",ans);}return 0;}17.Houseboat#include <stdio.h>#include <stdlib.h>#include <math.h>#define pi 3.1415926int f(float x,float y){int i;for(i=0;;i++)if(50*i>sqrt(x*x+y*y)*sqrt(x*x+y*y)*pi/2) break;return i;}int main(){int n,i,a[100];float x,y;scanf("%d",&n);for(i=0;i<n;i++){scanf("%f%f",&x,&y);a[i]=f(x,y);}for(i=0;i<n;i++)printf("%d %d\n",i+1,a[i]);return 0;}18.Music Composer19.Redistribute wealth#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int a[1000],b[1000],n,i,j,s,sum,t,m,mid,c[100],k=0;while(1){scanf("%d",&n);if(n==0) break;{s=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);s=s+a[i];}m=s/n;b[1]=a[1]-m;b[0]=0;for(i=2;i<n;++i)b[i]=b[i-1]+a[i]-m;for(i=0;i<n;i++)for(j=0;j<n-1-i;j++)if(b[j]>b[j+1]) t=b[j],b[j]=b[j+1],b[j+1]=t;mid=b[n/2];sum=0;for(i=0;i<=n-1;++i) sum=sum+fabs(mid-b[i]);c[k]=sum;k++;}}for(i=0;i<k;i++) printf("%d\n",c[i]);return 0;}20.Road trip#include <stdio.h>#include <stdlib.h>#include <math.h>int f(int n){int a[100],b[100],i,s;for(i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);s=a[0]*b[0];for(i=1;i<n;i++)s=s+a[i]*(b[i]-b[i-1]);return s;}int main(){int n,c[100],i=0;while(1){scanf("%d",&n);if(n==-1) break;c[i]=f(n);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",c[i]);return 0;}21.Scoring#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,j,sum,min,c,count,n,a,b;char s1[50],s2[50];scanf("%d",&n);for(i=0;i<n;i++){count=sum=0;scanf("%s",s2);for(j=0;j<4;j++){scanf("%d%d",&a,&b);if(b!=0){sum+=(a-1)*20+b;count++;}}if(i==0){c=count,min=sum;strcpy(s1,s2);}else if(count>c||(count==c&&sum<min)){min=sum;c=count;strcpy(s1,s2);}}printf("%s %d %d\n",s1,c,min);return 0;}22.Specialized Numbers#include <stdio.h>#include <stdlib.h>int main(){int i,n,sum10,sum12,sum16;for(i=2992;i<3000;i++){n=i;sum10=0;while(n){sum10+=n%10;n/=10;}n=i;sum12=0;while(n){sum12+=n%12;n/=12;}n=i;sum16=0;while(n){sum16+=n%16;n/=16;}if(sum10==sum12&&sum12==sum16) printf("%d\n",i);}return 0;}23.Sticks#include <stdio.h>#include <string.h>#include <stdlib.h>int len[64], n, minlen, get;bool b[64];int cmp(const void *a, const void *b){return *(int *)a < *(int *)b ? 1 : -1;}bool dfs(int nowlen, int nowget, int cnt){if(cnt >= n) return false;if(get == nowget) return true;int i;bool f = false;if(nowlen == 0) f = true;for(i = cnt; i < n; i++){if(!b[i]){if(len[i] + nowlen == minlen){b[i] = true;if(dfs(0, nowget+1, nowget))return true;b[i] = false;return false;}else if(len[i] + nowlen < minlen){b[i] = true;if(dfs(nowlen+len[i], nowget, i+1))return true;b[i] = false;if(f) return false;while(i + 1 < n && len[i] == len[i+1]) i++;}}}return false;}int main(){int i, tollen;while(scanf("%d", &n), n){tollen = 0;int j = 0, p;for(i = 0; i < n; i++){scanf("%d", &p);if(p <= 50)len[j] = p;tollen += len[j];j++;}}n = j;if(n == 0){printf("0\n");continue;}qsort(len, n, sizeof(int), cmp);for(minlen = len[0]; ; minlen++) {if(tollen % minlen) continue;memset(b, 0, sizeof(b));get = tollen / minlen;if(dfs(0, 0, 0)){printf("%d\n", minlen);break;}}return 0;}24.Sum of Consecutive#include <stdio.h>#include <stdlib.h>#include <string.h>int len[64],n,minlen,get;int b[64];int cmp(const void *a,const void *b) {return *(int *)a<*(int *)b?1:-1; }int dfs(int nowlen,int nowget,int cnt) {if(cnt>=n) return 0;if(get==nowget) return 1;int i,f=0;if(nowlen==0) f=1;for(i=cnt;i<n;i++){if(len[i]+nowlen==minlen){b[i]=1;if(dfs(0,nowget+1,nowget)) return 1;b[i]=0;return 0;}else if(len[i]+nowlen<minlen){b[i]=1;if(dfs(nowlen+len[i],nowget,i+1)) return 1;b[i]=0;if(f) return 0;while(i+1<n&&len[i]==len[i+1]) i++;}}return 0;}int main(){int i,tollen,q=0,c[100];while(scanf("%d",&n),n){tollen=0;int j=0,p;for(i=0;i<n;i++){scanf("%d",&p);if(p<=50){len[j]=p;tollen+=len[j];j++;}}n=j;if(n==0){printf("0\n"); continue;}qsort(len,n,sizeof(int),cmp); for(minlen=len[0];;minlen++){ if(tollen%minlen) continue;memset(b,0,sizeof(b));get=tollen/minlen;if(dfs(0,0,0)){c[q]=minlen;q++;break;}}}for(i=0;i<q;i++)printf("%d\n",c[i]);return 0;}25.Symmetric Sort#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){double A[100];int i=0,j=0,k=0,l=0,sum=0;while(1){scanf("%lf",&A[i]);if(A[i]==0)break;i++;}for(j=0;j<i;j++){if(A[j]==2)printf("1\n");else{int B[10000],m=1,number=0;double n;B[0]=2;for(k=3;k<=A[j];k+=2){n=(double)k;for(l=2;l<=sqrt(n);l++){if(k%l==0)goto ai;}B[m]=k;m++;ai:;}for(k=0;k<m;k++){sum=0;for(l=k;l<m;l++){sum+=B[l];if(sum==A[j]){number++;break;}}}printf("%d\n",number);}}return 0;}26.The Clock#include <stdio.h>#include <stdlib.h>#include <string.h>int main()char s[100][100],a[100];int i,j,n;scanf("%d",&n);for(i=0;i<n;i++) scanf("%s",s[i]);for(i=0;i<n-1;i++)for(j=0;j<n-1-i;j++)if(strlen(s[i])>strlen(s[i+1]))strcpy(a,s[i]),strcpy(s[i],s[i+1]),strcpy(s[i+1],a);if(n%2==0){for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-3;i>0;i=i-2) printf("%s ",s[i]);}else{for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-1;i>0;i=i-2) printf("%s ",s[i]);}return 0;}27.The Ratio of gainers to losers #include<stdio.h>int main(){char s[5];int i,sum=0;gets(s);for(i=0;s[i]!='\0';i++){switch(s[i]){case'I': sum+=1;break;case'V': sum=5-sum;break; case'X':sum=10-sum;break; }}printf("%d\n",sum);return 0;}28.VOL大学乒乓球比赛#include <stdio.h>#include <stdlib.h>int main(){printf("A=Z\nB=X\nC=Y\n");return 0;}29.毕业设计论文打印#include <stdio.h>#include <stdlib.h>int main(){int a[100],j=1,i,n,m;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)if(a[i]>a[m]) j++;printf("%d",j++);return 0;}30.边沿与内芯的差#include <stdio.h>#include <stdlib.h>int main(){int A[100][100],i,j,m,n,s=0,t=0;scanf("%d%d",&n,&m);for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&A[i][j]);}}for(i=2;i<m;i++)s=s+A[1][i];for(i=2;i<m;i++)s=s+A[n][i];for(i=1;i<=n;i++)s=s+A[i][1];for(i=1;i<=n;i++)。

西北工业大学C大作业第题

西北工业大学C大作业第题

作业名称:学生通讯录管理系统学院:自动化学院班级:学号:姓名:团队组成:西北工业大学2022年4月27日请填写以下十项内容,将表格按页对齐(插入空行),勿删除任何部分。

1、问题与背景(描述程序所要解决的问题或应用背景)2、开发工具(列出所使用的开发工具和第3方开发库)3、主要功能(详细说明程序的功能)4、设计内容(详细描述解决问题的原理和方法、算法、数据结构等)5、程序文件与工程名称(标出程序中所有文件名、工程名称及其说明)6、函数模块(程序中各个函数的原型声明及其说明)7、使用说明(运行程序的小型说明书)8、程序开发总结(简要叙述编写本作业的收获与思考)9、运行截图(附上程序运行的截图画面,至少有1幅,截图越翔实得分越高)增加联系人修改联系人删除联系人按学生姓名查询联系人按学生学号查询联系人保存通讯录打开通讯录10、源程序(附上程序源代码,若是多个文件,标出文件名)#include<string>#include<fstream>#include<iostream>#include<vector>using namespace std;static int n=0;struct student{string name;string number;string address;string telephone;string post;string mail;};class information{private:student st[10];public:void add(string name, string number,string address,string telephone,string post,string mail);void print(int i){cout<<"\t\t姓名:"<<st[i].name<<endl;cout<<"\t\t学号:"<<st[i].number<<endl;cout<<"\t\t地址:"<<st[i].address<<endl;cout<<"\t\t电话:"<<st[i].telephone<<endl;cout<<"\t\t邮编:"<<st[i].post<<endl;cout<<"\t\t邮箱:"<<st[i].mail<<endl;}void findname(string name);void findnumber(string number);void correct(string name);void del(string);void save();void read();};void information::add(string name, string number,string address,string telephone,string post,string mail){static int i=0;st[i].address=address;st[i].mail=mail;st[i].name=name;st[i].number=number;st[i].post=post;st[i].telephone=telephone;i++;n++;}void information::findname(string name){int x=0;for(int i=0;i<10;i++){if(st[i].name==name){print(i);x=1;break;}}if(x==0)cout<<"the man can.t be found in the record!"<<endl;}void information::findnumber(string number){for(int i=0;i<10;i++){if(st[i].number==number){print(i);x=1;break;}}if(x==0)cout<<"the student can.t be found in the record!"<<endl; }void information::correct(string name){string number;string address;string telephone;string post;string mail;int x=0;for(int i=0;i<10;i++){if(st[i].name==name){cout<<"\t输入要修改的姓名:";cin>>name;st[i].name=name;cout<<"\t输入要修改的学号:";cin>>number;st[i].number=number;cout<<"\t输入要修改的地址:";cin>>address;st[i].address=address;cout<<"\t输入要修改的电话:";cin>>telephone;st[i].telephone=telephone;cout<<"\t输入要修改的邮编:";cin>>post;st[i].post=post;cout<<"\t输入要修改的邮箱:";cin>>mail;st[i].mail=mail;print(i);x=1;}if(x==0)cout<<"the man can.t be found in the record"<<endl;}void information::del(string name){int x=0;for(int i=0;i<10;i++){if(st[i].name==name){st[i].address="0";st[i].mail="0";st[i].name="0";st[i].number="0";st[i].post="0";st[i].telephone="0";x=1;print(i);}}if(x==0)cout<<"the student can.t be found in the record"<<endl;}void information::save(){string fileName;second:cout<<"\t输入要保存的文件名:";cin>>fileName;ofstream outFile(fileName.c_str());if(!outFile){cerr<<"\terror:unable to open output file: "<<fileName<<endl; goto second;}for(int i=0;i<n;i++){outFile << "姓名:"<<st[i].name<<"\t";outFile << "学号:"<<st[i].number<<"\t";outFile << "地址:"<<st[i].address<<"\t";outFile << "电话号码:"<<st[i].telephone<<"\t";outFile << "邮编:"<<st[i].post<<"\t";outFile << "E_MAIL:"<<st[i].mail<<endl;}outFile.close();}void information::read(){vector<string> svec;string fileName,s;cin>>fileName;ifstream inFile(fileName.c_str());if(!inFile){cerr<<"\terror:unable to open output file: "<<fileName<<endl;}while(getline(inFile,s))svec.push_back(s);for(vector<string>::iterator iter=svec.begin();iter!=svec.end();++iter)cout<<*iter<<endl<<endl;}int main(){information s;cout<<"\t★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★"<<endl; cout<<endl;cout<<"\t\t\twelcome to use the communication book"<<endl;cout<<"\t\t\t\t\t\tdesigned: 郭振超"<<endl;cout<<"\t\t----------------------------------------------------"<<endl;begin:cout<<"\t\t| 1.编辑通信录 2.查询联系人 |"<<endl;cout<<"\t\t| 3.保存通信录 4.打开通记录 |"<<endl;cout<<"\t\t----------------------------------------------------"<<endl;string name;string number;string address;string telephone;string post;string mail;int val1;cout<<"\t\t请选择功能号:";cin>>val1;switch(val1){case 1:cout<<"\t\t(1) 增加联系人"<<endl;cout<<"\t\t(2) 修改联系人"<<endl;cout<<"\t\t(3) 删除联系人"<<endl;int val2;cout<<"\t\t请选择选项:";cin>>val2;switch(val2){case 1:cout<<"\t 输入姓名: ";cin>>name;cout<<"\t 输入学号: ";cin>>number;cout<<"\t 输入地址: ";cin>>address;cout<<"\t 输入电话: ";cin>>telephone;cout<<"\t 输入邮编: ";cin>>post;cout<<"\t 输入邮箱: ";cin>>mail;s.add(name,number,address,telephone,post,mail); cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_add;cin>>back_add;if(back_add!=0)goto begin;elsegoto end;break;case 2:cout<<"\t请输入要修改的学生姓名:";cin>>name;s.correct(name);cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_correct;cin>>back_correct;if(back_correct!=0)goto begin;elsegoto end;break;case 3:cout<<"\t请输入要删除的学生信息的学生姓名:"; cin>>name;s.del(name);cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_del;cin>>back_del;if(back_del!=0)goto begin;elsegoto end;break;}break;case 2:cout<<"\t\t(1) 按学生姓名查询"<<endl;cout<<"\t\t(2) 按学生学号查询"<<endl;int val3;cout<<"\t\t请选择选项:";cin>>val3;switch(val3){case 1:cout<<"\t请输入查询的学生姓名:";cin>>name;s.findname(name);cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_findname;cin>>back_findname;if(back_findname!=0)goto begin;elsegoto end;break;case 2:cout<<"\t请输入查询的学生学号:";cin>>number;s.findnumber(number);cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_findnumber;cin>>back_findnumber;if(back_findnumber!=0)goto begin;elsegoto end;break;}break;case 3:cout<<"\t确定保存修改的记录吗(请输入y或n进行选择):"; char val4;cin>>val4;if(val4=='n'){cout<<"放弃记录保存!"<<endl;cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_save;cin>>back_save;if(back_save!=0)goto begin;elsegoto end;}else{s.save();cout<<"\t保存成功!"<<endl;cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_save;cin>>back_save;if(back_save!=0)goto begin;elsegoto end;}break;case 4:cout<<"\t输入要打开的记录名:";s.read();cout<<"\t\t按0键退出系统,按其他键返回主菜单:";int back_read;cin>>back_read;if(back_read!=0)goto begin;elsegoto end;break;}end:cout<<"\t**********成功退出系统,欢迎再次使用!**********"<<endl; return 0;}。

c语言试题含答案

c语言试题含答案

西北工业大学印制
共 9 页
第 3 页
3.写出下面程序的运行结果。 #include <stdio.h> void main() { int k=1,n=263 ; do { k*= n%10 ; n/=10 ; } while (n) ; printf("%d\n",k); } 4.下面程序的功能是:将 n 个无序整数从小到大排序;判断下面程序的正误,如果错误请改正过来。 #include <stdio.h> void main() { int a[100], i, j, p, t, n=20 ; for ( j = 0; j<n ; j++ ) scanf(”%d”, &a[j]), for ( j = 0; j<n-1 ; j++ ) { p = j; for ( i=j+1; i<n-1 ; i++ ) if ( a[p]>a[i] ) t=i; if ( p!=j ) { t = a[j]; a[j] = a[p]; a[p] = t; } } for ( j = 0; j<n ; j++ ) printf(”%d” &a[j]); , }
。 的值是 b

17.将文件指针移到文件当前位置前 40 个字节的 C 语言语句是 指针移到文件当前位置后 10 个字节的 C 语言语句是 三、综合题(每题 6 分,5 小题,共 30 分) 1.写出下面程序执行后的运行结果。 #include <stdio.h> void main() { int y=3,x=3,z=1; printf("%d %d\n",(++x,y++),z+2); } 。

西工大NOJ答案完全版

西工大NOJ答案完全版

输出A+B的结黑#i nclude<stdio.h>int main(){int a,b,sum;sca nf("%d%d",&a,&b);sum=a+b;prin tf("%d\n",sum); return 0; }#i nclude<stdio.h>#define PI 3.1415926int main(){double r,h,l,s,sq,vq,vz;sca nf("%lf%lf",&r,&h);l=2*PI*r;s=p|*r*r;sq=4*p|*r*r;vq=PI*r*r*r*4/3;vz=PI*r*r*h;prin tf("%.2lf\n%.2lf\n%.2lf\n%.2lf\n%.2lf\n",l,s,sq,vq,vz); return 0;}#i nclude<stdio.h>int main(){double ma,e ng,c,sum,ave;sca nf("%lf%lf%lf",&ma,&en g,&c); sum=ma+e ng+c; ave=sum/3;prin tf("%lf\n %lf\n",sum,ave); return 0;}#i nclude<stdio.h>int main(){int a,b,c,m;sca nf("%d%d%d",&a,&b,&c); if (a>b) m=a;else m=b;if (m<c) m=c;prin tf("%d",m);return 0;}#i nclude<stdio.h>int main(){int n;sca nf("%d",&n);if ((1000V n<10000)&&(n/1000==n%10)&&(n/100%10==n/10%10)) prin tf("y es\n");else if((100<n<=1000)&&(n/100==n%10)) printf("yes\n");else if((10< n <=100)&&(n/10==n%10)) pri ntf("yes\n");else if(0< n<=10) pri ntf("yes\n");else prin tf(" no\n");return 0;}#i nclude<stdio.h>int main(){double l,b on;sca nf("%lf",&l);if(|v=10) bon=1*0.1;else if(l<20) bo n=1+(l-10)*0.075; else if(l<40) bon=1.75+(1-20)*0.05; else if(l<60) bon=2.75+(1-40)*0.03; else if(l<100) bon=3.35+(1-60)*0.015; else bo n=3.95+(l-100)*0.01;prin tf("%lf\n",bo n);return 0;}输出为实型,帰留六惶小裁(单位为元)#i nclude<stdio.h>int main(){double d,m;sca nf("%lf",&d);if(d<=2) m=7;else if(d<=15){if(d-2==(i nt)(d-2)) m=7+(d-2)*1.5;else m=7+((i nt)(d-2)+1)*1.5;}else if(d-15==(int)(d-15)) m=26.5+(d-15)*2.1; else m=26.5+((i nt)(d-15)+1)*2.1;prin tf("%lf\n",m);return 0;}#i nclude<stdio.h>int main(){int y,m,d,Days,sum;sca nf("%d-%d-%d", &y,&m,&d);if((y%4==0&&y%100!=0)||(y%400==0)) Days=29; else Days=28; switch(m){case 1:sum=d;break;case 2:sum=31+d;break;case 3:sum=31+Days+d;break;case 4:sum=62+Days+d;break;case 5:sum=92+Days+d;break;case 6:sum=123+Days+d;break;case 7:sum=153+Days+d;break;case 8:sum=184+Days+d;break;case 9:sum=215+Days+d;break;case 10:sum=245+Days+d;break;case 11:sum=276+Days+d;break;case 12:sum=307+Days+d;break;}prin tf("%d\n",sum);return 0;}#i nclude<stdio.h>int main(){int i;sca nf("%d",&i);if(i>=90) prin tf("A\n");else if(i>=80) prin tf("B\n"); else if(i>=70) pri ntf("C\n"); else if(i>=60) prin tf("D\n"); else prin tf("E\n");return 0;}#i nclude<stdio.h>int main(){double x,y;sca nf("%lf,%lf", &x,&y);if((x-2)*(x-2)+(y-2)*(y-2)v=1) prin tf("10");else if((x-2)*(x-2)+(y+2)*(y+2)<=1) printf("10"); else if((x+2)*(x+2)+(y-2)*(y-2)<=1) printf("10"); else if((x+2)*(x+2)+(y+2)*(y+2)<=1) printf("10"); else prin tf("0");return 0;}输出根炬型・保留两性呷数.#i nclude<stdio.h>int main(){double l,x,r;sca nf("%lf %lf",&l,&r);while((2*l*l*l-4*l*l+3*l-6)!=0&&(2*r*r*r-4*r*r+3*r-6)!=0){ x=(l+r)/2;if((2*l*l*l-4*l*l+3*l-6)*(2*x*x*x-4*x*x+3*x-6)<=0)r=x;else l=x;}if(2*l*l*l-4*l*l+3*l-6==0) prin tf("%.2lf",l);else prin tf("%.2lf",r);return 0;}}#i nclude<stdio.h>#in clude<math.h>int main(){int i=800,t=2,c nt=0,sum=0;double e=-1;while(i>=500){while(t<=i-1){if(i%t==0) break;t++;}if(t==i) e=pow(-1,c nt),sum=sum+e*i,cnt++; i--;t=2;}prin tf("%d %d",cnt,sum);return 0;#i nclude<stdio.h>#in clude<math.h> int main(){int a=1;double b=1,pi=0,c=1;while(fabs(c)>=1e-6)pi=pi+c,b=b+2,a=-a,c=a/b; pi=pi*4; prin tf("%lf\n",pi); return 0;}}#i nclude<stdio.h>int main(){int a仁1,a2=1,n=2,sum=2,t; while(sum<=100){t=a1;a仁a2;a2=t+2*a2; sum=sum+a2;n++;}prin tf("%d\n", n-1);while(sum<=1000){t=a1;a仁a2;a2=t+2*a2; sum=sum+a2;n++;}prin tf("%d\n", n-1);while(sum<=10000){t=a1;a仁a2;a2=t+2*a2;}sum=sum+a2; n++;}prin tf("%d\n", n-1);}File Name :T01 Sxpp最次方数输出为整型.#i nclude<stdio.h>int main(){int x,a,s, n=1;scanf("%d %d",&x,&a);s=x;if(a!=O){for(; n<a;n++){s=s*x;if(s>=1000) s=s/100%10*100+s/10%10*10+s%10;}}prin tf("%d\n",s);return 0;輸出连腹奇蒙之和,格式如sa mple outputB示.#i nclude<stdio.h>int main(){int m, n,s;scan f("%d",&n);s=n*n*n;prin tf("%d*%d*%d=%d=" ,n,n,n ,s);for(m=1;s!=n*m;m++);if(n %2==1){for(s=-n/2;s< n/2;s++)pri ntf("%d+",m+2*s);prin tf("%d",m+n/2*2);}else{for(s=-n/2;s< n/2-1;s++)pri ntf("%d+",m+s*2+1); prin tf("%d",m+( n/2-1)*2+1);}}#i nclude<stdio.h>int main(){char a,b,c,x,y, z; a='A',b='B',c=C,x='X',y='Y',z='Z'; prin tf("%c=%c\n",a,z);prin tf("%c=%c\n",b,x);prin tf("%c=%c\n",c,y); return 0;}#i nclude<stdio.h>int main(){int a,b,t;sca nf("%d %d",&a,&b); if(a>b)t=a,a=b,b=t;for(;a<b;a++){ for(t=2;t<a;t++)if(a%t==0) break; if(t==a)pri ntf("%d ",a); }return 0;}#i nclude<stdio.h>int main(){int n=1;double a1= 1,a2=2,a3,sum=2; while( n<=19){a3=a1+a2;sum=sum+a3/a2;a仁a2;a2=a3;n++;}prin tf("%lf\n",sum);return 0;}}Input#i nclude<stdio.h>#in clude<math.h> int main() {double a;int n=0;sca nf("%lf",&a); a=fabs(a); if(a<=1)pri ntf("0\n"); else{while(a>1){ a=a/10;n++;}prin tf("%d\n", n);}#i nclude<stdio.h>int main(){int a=1,b=0,t, m,n=0; sca nf("%d", &t); while( n< t){ m=b; b=3*a+2*b;a=m;n++;}prin tf("%d %d",a,b); return 0;}}输出旅苣方法的数目#i nclude<stdio.h>#in clude<math.h> int main(){int n;int f(i nt n);sca nf("%d",&n);prin tf("%d\n",f( n));}int f(i nt n){int a;if(n==1|| n==2)a=0;else if(n==3)a=1;else if(n==4)a=3;elsea=f( n-1)*2+pow(2, n-4)-f( n-4); return a; }#i nclude<stdio.h>int main(){int n ,x=1234,y=1,a,b,c,d,e,f,g,h,i,j;sca nf("%d",&n);for(;x<49383&&y<98765;x++){y=x* n;a=x/10000%10; b=x/1000%10;c=x/100%10; d=x/10%10;e=x%10;f=y/10000%10; g=y/1000%10;h=y/100%10;i=y/10%10;j=y%10; if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==j) con ti nue;if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==j) con ti nue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==j) con ti nue;if(d==e||d==f||d==g||d==h||d==i||d==j) con ti nue; if(e==f||e==g||e==h||e==i||e==j) con ti nue; if(f==g||f==h||f==i||f==j) con ti nue;if(g==h||g==i||g==j) continue;if(h==i||h==j) continue;if(i==j) continue;prin tf("%05d/%05d=%d\n",y,x, n); }return 0;}1 1 1/+(科十iy + +歹輪出计算绪果,赧鈕5粒小薮.#i nclude<stdio.h>#i nclude<stdlib.h>#in clude<math.h> int main(){in t m,n ,i;double x,s=0;sca nf("%d%d",&n,&m);for(i=n ;i<=m;i++){x=pow(i,2.0); s=s+1/x;}prin tf("%.5lf\n",s); return 0;}#i nclude<stdio.h>int main(){int x,y,a,b,L;double t;scan f("%d%d%d%d%d", &x, &y,&a,&b,&L); if(a==b) prin tf("impossible\n");else if(x>y){ if(a>b)y=L-x+y,t=(double)y/(a-b); else y=x-y,t=(double)y/(b-a);if((i nt)t==t)pri ntf("%d\n",(i nt)t); else prin tf("%lf\n",t);}else { if(a>b)y=y-x,t=(double)y/(a-b); else y=L-y+x,t=(double)y/(b-a); if((i nt)t==t)pri ntf("%d\n",(i nt)t); else prin tf("%lf\n",t);}return 0;}#i nclude<stdio.h>int _max(i nt a,i nt b){ _retur n a>b?a:b;}int a[20];int f[20][20];int main(){int n ,i,j,s=0;sca nf("%d",&n);for(i=0;i< n;i++)scan f("%d",&a[i]);for(j=1;j< n;j++)f[0][0]=a[0],f[0][j]=f[0][j-1]*a[j]; for(i=1;i< n;i++){f[i][i-1]=1;for(j=i;j< n;j++)f[i][j]=f[i][j-1]*a[j];}for(i=0;i< n;i++) for(j=i;j< n;j++) s=_max(s,f[i][j]);if(s==O)pri ntf("-1\n"); else prin tf("%d\n",s); return 0;}#i nclude<stdio.h>int main(){int x=192,y, z,a,b,c,d,e,f,g,h,i;for(;x<328;x++){y=2*x;z=3*x;a=x/100%10;b=x/10%10;c=x%10;d=y/100%10;e=y/10%10;f=y%10;g=z/100%10;h=z/10%10;i=z%10;if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==0) con ti nue;if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==0) con ti nue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==0) con ti nue;if(d==e||d==f||d==g||d==h||d==i||d==0) con ti nue;if(e==f||e==g||e==h||e==i||e==O) con ti nue; if(f==g||f==h||f==i||f==O) con ti nue; if(g==h||g==i||g==O) con ti nue; if(h==i||h==O) continue;prin tf("%d %d %d\n",x,y,z);}return 0;}#i nclude<stdio.h>int main(){int a,b,c,sum=10;sca nf("%d%d%d",&a,&b,&c);for(;sum<=100;sum++){if(sum%3==a&&sum%5==b&&sum%7==c){ prin tf("%d\n",sum); break;}}if(sum==101)pri ntf("-1\n");return 0;}輸出合敎世圮起始导殆束年檢,用空恪隔开#i nclude<stdio.h>#in clude<math.h>int main(){int ce,y,m, n,a=0;sca nf("%d",&n); for(ce=0;;ce+=100){for(y=ce+1;y<ce+100;y+=2){ for(m=3;m<sqrt(y);m+=2){ if(y%m==0) break;}if(m>=sqrt(y)) break;}if(y==ce+101) a++;if(a==n) break;}prin tf("%d %d\n",ce,ce+99); return 0;}{int n,i;sca nf("%d",&n);for(i=1;i<=n ;i++){if(i%7==0) pri ntf("%d ",i);else if(i/1000%10==7||i/100%10==7||i/10%10==7||i%10==7) printf("%d ",i ); }return 0;}#i nclude<stdio.h>double a[100000000];int main(){int n,i;double ave,sum=0;sca nf("%d",&n);for(i=0;i< n;i++){scan f("%lf",&a[i]); sum=sum+a[i];}ave=su m/n;for(i=0,sum=0;i <n ;i++) sum=sum+(a[i]-ave)*(a[i]-ave); prin tf("%lf\n",sum); return 0;}int f[100000000];int main(){int n,i;sca nf("%d",&n);for(i=0;i< n;i++){int a,b;scan f("%d%d",&a,&b);f[i]=a+b;}for(i=0;i< n;i++){if(f[i]>100) f[i]=f[i]/10%10*10+f[i]%10,pri ntf("%d\n",f[i]); else prin tf("%d\n",f[i]); }return 0;}ttinc-udeAsfdio.hvttinc-udeAmafh.hvinfn H n v v k t八「efumn QO —k八inf main。

西工大noj答案完整版

西工大noj答案完整版

西北工业大学POJ答案绝对是史上最全版(不止100题哦……按首字母排序)1.“1“的传奇2.A+B3.A+BⅡ4.AB5.ACKERMAN6.Arithmetic Progressions7.Bee8.Checksum algorithm9.Coin Test10.Dexter need help11.Double12.Easy problem13.Favorite number14.Graveyard15.Hailstone16.Hanoi Ⅱ17.Houseboat18.Music Composer19.Redistribute wealth20.Road trip21.Scoring22.Specialized Numbers23.Sticks24.Sum of Consecutive25.Symmetric Sort26.The Clock27.The Ratio of gainers to losers28.VOL大学乒乓球比赛29.毕业设计论文打印30.边沿与内芯的差31.不会吧,又是A+B32.不屈的小蜗33.操场训练34.插入链表节点35.插入排序36.插入字符37.成绩表计算38.成绩转换39.出租车费40.除法41.创建与遍历职工链表42.大数乘法43.大数除法44.大数加法45.单词频次46.迭代求根47.多项式的猜想48.二分查找49.二分求根50.发工资的日子51.方差52.分离单词53.分数拆分54.分数化小数55.分数加减法56.复数57.高低交换58.公园喷水器59.韩信点兵60.行程编码压缩算法61.合并字符串62.猴子分桃63.火车站64.获取指定二进制位65.积分计算66.级数和67.计算A+B68.计算PI69.计算π70.计算成绩71.计算完全数72.检测位图长宽73.检查图像文件格式74.奖金发放75.阶乘合计76.解不等式77.精确幂乘78.恐怖水母79.快速排序80.粒子裂变81.链表动态增长或缩短82.链表节点删除83.两个整数之间所有的素数84.路痴85.冒泡排序86.你会存钱吗87.逆序整数88.排列89.排列分析90.平均值函数91.奇特的分数数列92.求建筑高度93.区间内素数94.三点顺序95.山迪的麻烦96.删除字符97.是该年的第几天98.是该年的第几天?99.数据加密100.搜索字符101.所有素数102.探索合数世纪103.特殊要求的字符串104.特殊整数105.完全数106.王的对抗107.危险的组合108.文件比较109.文章统计110.五猴分桃111.小型数据库112.幸运儿113.幸运数字”7“114.选择排序115.寻找规律116.循环移位117.延伸的卡片118.羊羊聚会119.一维数组”赋值“120.一维数组”加法“121.勇闯天涯122.右上角123.右下角124.圆及圆球等的相关计算125.圆及圆球等相关计算126.程序员添加行号127.找出数字128.找幸运数129.找最大数130.整数位数131.重组字符串132.子序列的和133.子字符串替换134.自然数立方的乐趣135.字符串比较136.字符串复制137.字符串加密编码138.字符串逆序139.字符串排序140.字符串替换141.字符串左中右142.组合数143.最次方数144.最大乘积145.最大整数146.最小整数147.最长回文子串148.左上角149.左下角1.“1“的传奇#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int n,i,j,k=0,x=1,y,z,m,p,q,a,s=0;scanf("%d",&n);m=n;for(i=1;i<12;i++){m=m/10;k++;if(m==0)break;}q=n;k=k-1;for(a=1;a<=k;a++){x=x*10;}y=q%x;z=q/x;p=q-y;if(z>=2)s=s+x+z*k*(x/10); elses=s+z*k*(x/10);for(j=p;j<=n;j++) {m=j;for(i=1;i<12;i++){x=m%10;if(x==1)s++;m=m/10;if(m==0)break;}}printf("%d",s);return 0;}2.A+B#include <stdio.h>int doubi(int n,int m){n=n+m;n=n%100;return n;}int main(){int t,i,a[100],n,m;scanf("%d",&t);for (i=0;i<=(t-1);i++){scanf("%d%d",&n,&m);a[i]=doubi(n,m);}for (i=0;i<=(t-1);i++)printf("%d\n",a[i]);return 0;}3.A+BⅡ#include <stdio.h>int main(){int A,B,sum;scanf("%d%d",&A,&B);sum=A+B;printf("%d\n",sum);return 0;}4.AB#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){char s[100],q[100];double a,b,c;int n=0,i;scanf("%lf%lf",&a,&b);c=a*b;sprintf(s,"%.0lf",c);for(i=0;i<strlen(s);i++){n=n+s[i]-48;}while(n>=10){sprintf(q,"%d",n);n=0;for(i=0;i<strlen(q);i++)n=n+q[i]-48;}printf("%d",n);return 0;}5.ACKERMAN#include <stdio.h>#include <stdlib.h>int ack(int x,int y){int n;if (x==0) {n=y+1;return n;}else if (y==0) n=ack(x-1,1);else n=ack(x-1,ack(x,y-1));return n;}int main(){int m,b;scanf("%d%d",&m,&b);m=ack(m,b);printf("%d",m);return 0;}6.Arithmetic Progressions#include <stdio.h>#include <math.h>int g(int n){int i;if(n==1) return 0;if(n==2) return 1;if(n==3) return 1;for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0;return 1;}int f(int a,int b,int c){int i=0,s=a-b;if(c==1&&g(a)==1) return a;if(b==0&&g(a)!=1) return -1;while(1){s=s+b;if(g(s)) i++;if(i>=c) break;}return s;int main(){int a,b,c,d[100],i=0,n;while(1){scanf("%d%d%d",&a,&b,&c);if(a==0&&b==0&&c==0) break;d[i]=f(a,b,c);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",d[i]);return 0;}7.Bee#include <stdio.h>#include <stdlib.h>int main()int A[100],i=0,j,k,female=0,male=1,x;for(;;i++){scanf("%d",&A[i]);if(A[i]==-1)break;}for(j=0;j<i;j++){female=0,male=1;for(k=1;k<A[j];k++){x=female;female=male;male=x+male+1;}printf("%d %d\n",male,female+male+1);}return 0;}8.Checksum algorithm #include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,n,t,j;char s[100][100];for(i=0;;i++){gets(s[i]);if(s[i][0]=='#') break;}n=i;for(i=0;i<n;i++){t=0;for(j=0;j<strlen(s[i]);j++)if(s[i][j]==32) t=t;else t=t+(j+1)*(s[i][j]-64);printf("%d\n",t);}return 0;}9.Coin Test#include <stdio.h>#include <stdlib.h>int main(){char A[100000];int n,i=0,a=0,b=0,j;double x;while(1){scanf("%c",&A[i]);if(A[i]=='\n')break;i++;}for(j=0;j<i;j++){if(A[j]=='S'){printf("WA");goto OH;}if(A[j]=='U')a++;if(A[j]=='D')b++;}x=a*1.0/(a+b)*1.0;if(x-0.5>0.003||x-0.5<-0.003) printf("Fail");elseprintf("%d/%d",a,a+b);OH:return 0;}10.Dexter need help#include <stdio.h>int fun(int a){if(a==1) return 1;elsereturn fun(a/2)+1;}int main(){int a,b[100],i=0,j; while(1){scanf("%d",&a);if(a==0)break;b[i]=fun(a);i++;}for(j=0;j<i;j++){printf("%d\n",b[j]); }return 0;}11.Double#include <stdio.h>#include <stdlib.h>int main(){int a[100],b[100],i,j,n,t=0;for(i=0;;i++){scanf("%d",&a[i]);if(a[i]==0) break;}n=i;for(i=0;i<n;i++)b[i]=2*a[i];for(i=0;i<n;i++)for(j=0;j<n;j++)if(a[i]==b[j]) t++;printf("%d",t);return 0;}12.Easy problem#include <stdio.h>#include <math.h>int main(){int N,i,n,j=0;scanf("%d",&N);for(i=2;i<N+1;i++){if((N+1)%i==0)j++;}printf("%d",j/2);return 0;}13.Favorite number #include <stdio.h>#include <string.h>#define MAXNUM 100000int prime_number = 0;int prime_list[MAXNUM]; bool is_prime[MAXNUM]; int ans[MAXNUM + 2];int dp[MAXNUM + 2];void set_prime() {int i, j;memset(is_prime, 0, sizeof(is_prime));for (i = 2; i < MAXNUM; i++) {if (is_prime[i] == 0) {prime_list[prime_number++] = i;if (i >= MAXNUM / i) continue;for (j = i * i; j < MAXNUM; j+=i) {is_prime[j] = 1;}}}}int main() {int i, j, k,o=0,d[100];memset(dp, -1, sizeof(dp));set_prime();ans[0] = 0;dp[1] = 0;for (i = 1; i <= MAXNUM; i++) {ans[i] = ans[i - 1] + dp[i];if (dp[i + 1] == -1 || dp[i + 1] > dp[i] + 1) { dp[i + 1] = dp[i] + 1;}for (j = 0; j < prime_number; j++) {if (i > MAXNUM / prime_list[j]) break;k = i * prime_list[j];if (dp[k] == -1 || dp[k] > dp[i] + 1) {dp[k] = dp[i] + 1;}}}while (scanf("%d%d", &i, &j) == 2 && (i || j)) { d[o]=ans[j] - ans[i - 1];o++;}for(i=0;i<o;i++)printf("%d\n",d[i]);}14.Graveyard#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int a[100],b[100],n,i,j;double s,p,l,t;for(i=0;;i++){scanf("%d%d",&a[i],&b[i]);if(a[i]==0&&b[i]==0) break;}n=i;for(i=0;i<n;i++){p=10000;if(b[i]%a[i]==0){printf("0.0000\n");continue;};t=10000/((double)a[i]);for(j=1;j<a[i]+b[i];j++){l=10000/((double)(a[i]+b[i]));l=t-j*l;l=fabs(l);if(l<p) p=l;}s=(a[i]-1)*p;printf("%.4lf\n",s);}return 0;}15.Hailstone#include <stdio.h>#include <stdlib.h>#include <string.h>int f(int n){int s=1;while(1){if(n==1) return s;else if(n%2==0) n=n/2,s++;else n=3*n+1,s++;}}int main()int n,m,i,j=0,t;scanf("%d%d",&m,&n);printf("%d %d",m,n);if(m>n) t=m,m=n,n=t;for(i=m;i<=n;i++)if(f(i)>j) j=f(i);printf(" %d",j);return 0;}16.Hanoi Ⅱ#include <stdio.h>#include <stdlib.h>#define M 70int start[M], targe[M];long long f(int *p, int k, int fina){if(k==0) return 0;if(p[k]==fina) return f(p,k-1,fina); return f(p,k-1,6-fina-p[k])+(1LL<<(k-1));int main (){long long ans;int n;while(scanf("%d",&n),n){int i;for(i=1;i<=n;i++) scanf("%d",&start[i]);for(i=1;i<=n;i++) scanf("%d",&targe[i]);int c=n;for(;c>=1&&start[c]==targe[c];c--);if(c==0){printf("0\n"); continue;}int other=6-start[c]-targe[c];ans=f(start,c-1,other)+f(targe,c-1,other)+1;printf("%lld\n",ans);}return 0;}17.Houseboat#include <stdio.h>#include <stdlib.h>#include <math.h>#define pi 3.1415926int f(float x,float y){int i;for(i=0;;i++)if(50*i>sqrt(x*x+y*y)*sqrt(x*x+y*y)*pi/2) break;return i;}int main(){int n,i,a[100];float x,y;scanf("%d",&n);for(i=0;i<n;i++){scanf("%f%f",&x,&y);a[i]=f(x,y);}for(i=0;i<n;i++)printf("%d %d\n",i+1,a[i]);return 0;}18.Music Composer19.Redistribute wealth#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int a[1000],b[1000],n,i,j,s,sum,t,m,mid,c[100],k=0;while(1){scanf("%d",&n);if(n==0) break;{s=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);s=s+a[i];}m=s/n;b[1]=a[1]-m;b[0]=0;for(i=2;i<n;++i)b[i]=b[i-1]+a[i]-m;for(i=0;i<n;i++)for(j=0;j<n-1-i;j++)if(b[j]>b[j+1])t=b[j],b[j]=b[j+1],b[j+1]=t;mid=b[n/2];sum=0;for(i=0;i<=n-1;++i) sum=sum+fabs(mid-b[i]);c[k]=sum;k++;}}for(i=0;i<k;i++) printf("%d\n",c[i]);return 0;}20.Road trip#include <stdio.h>#include <stdlib.h>#include <math.h>int f(int n){int a[100],b[100],i,s;for(i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);s=a[0]*b[0];for(i=1;i<n;i++)s=s+a[i]*(b[i]-b[i-1]);return s;}int main(){int n,c[100],i=0;while(1){scanf("%d",&n);if(n==-1) break;c[i]=f(n);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",c[i]);return 0;}21.Scoring#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,j,sum,min,c,count,n,a,b;char s1[50],s2[50];scanf("%d",&n);for(i=0;i<n;i++){count=sum=0;scanf("%s",s2);for(j=0;j<4;j++){scanf("%d%d",&a,&b);if(b!=0){sum+=(a-1)*20+b;count++;}}if(i==0){c=count,min=sum;strcpy(s1,s2);}else if(count>c||(count==c&&sum<min)){min=sum;c=count;strcpy(s1,s2);}}printf("%s %d %d\n",s1,c,min);return 0;}22.Specialized Numbers#include <stdio.h>#include <stdlib.h>int main(){int i,n,sum10,sum12,sum16;for(i=2992;i<3000;i++){n=i;sum10=0;while(n){sum10+=n%10;n/=10;}n=i;sum12=0;while(n){sum12+=n%12;n/=12;}n=i;sum16=0;while(n){sum16+=n%16;n/=16;}if(sum10==sum12&&sum12==sum16) printf("%d\n",i);}return 0;}23.Sticks#include <stdio.h>#include <string.h>#include <stdlib.h>int len[64], n, minlen, get;bool b[64];int cmp(const void *a, const void *b){return *(int *)a < *(int *)b ? 1 : -1;}bool dfs(int nowlen, int nowget, int cnt){if(cnt >= n) return false;if(get == nowget) return true;int i;bool f = false;if(nowlen == 0) f = true;for(i = cnt; i < n; i++){if(!b[i]){if(len[i] + nowlen == minlen){b[i] = true;if(dfs(0, nowget+1, nowget))return true;b[i] = false;return false;}else if(len[i] + nowlen < minlen){b[i] = true;if(dfs(nowlen+len[i], nowget, i+1))return true;b[i] = false;if(f) return false;while(i + 1 < n && len[i] == len[i+1]) i++;}}}return false;}int main(){int i, tollen;while(scanf("%d", &n), n){tollen = 0;int j = 0, p;for(i = 0; i < n; i++){scanf("%d", &p);if(p <= 50){len[j] = p;tollen += len[j];j++;}}n = j;if(n == 0){printf("0\n");continue;}qsort(len, n, sizeof(int), cmp);for(minlen = len[0]; ; minlen++) {if(tollen % minlen) continue;memset(b, 0, sizeof(b));get = tollen / minlen;if(dfs(0, 0, 0)){printf("%d\n", minlen);break;}}}return 0;}24.Sum of Consecutive#include <stdio.h>#include <stdlib.h>#include <string.h>int len[64],n,minlen,get;int b[64];int cmp(const void *a,const void *b) {return *(int *)a<*(int *)b?1:-1;}int dfs(int nowlen,int nowget,int cnt) {if(cnt>=n) return 0;if(get==nowget) return 1;int i,f=0;if(nowlen==0) f=1;for(i=cnt;i<n;i++){if(len[i]+nowlen==minlen){b[i]=1;if(dfs(0,nowget+1,nowget)) return 1;b[i]=0;return 0;}else if(len[i]+nowlen<minlen){b[i]=1;if(dfs(nowlen+len[i],nowget,i+1)) return 1;b[i]=0;if(f) return 0;while(i+1<n&&len[i]==len[i+1]) i++;}}return 0;}int main(){int i,tollen,q=0,c[100];while(scanf("%d",&n),n){tollen=0;int j=0,p;for(i=0;i<n;i++){scanf("%d",&p);if(p<=50){len[j]=p;tollen+=len[j];j++;}}n=j;if(n==0){printf("0\n");continue;}qsort(len,n,sizeof(int),cmp);for(minlen=len[0];;minlen++){if(tollen%minlen) continue;memset(b,0,sizeof(b));get=tollen/minlen;if(dfs(0,0,0)){c[q]=minlen;q++;break;}}}for(i=0;i<q;i++)printf("%d\n",c[i]);return 0;}25.Symmetric Sort#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){double A[100];int i=0,j=0,k=0,l=0,sum=0;while(1){scanf("%lf",&A[i]);if(A[i]==0)break;i++;}for(j=0;j<i;j++){if(A[j]==2)printf("1\n");else{int B[10000],m=1,number=0;double n;B[0]=2;for(k=3;k<=A[j];k+=2){n=(double)k;for(l=2;l<=sqrt(n);l++){if(k%l==0)goto ai;}B[m]=k;m++;ai:;}for(k=0;k<m;k++){sum=0;for(l=k;l<m;l++){sum+=B[l];if(sum==A[j]){number++;break;}}}printf("%d\n",number);}}return 0;}26.The Clock#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){char s[100][100],a[100];int i,j,n;scanf("%d",&n);for(i=0;i<n;i++) scanf("%s",s[i]);for(i=0;i<n-1;i++)for(j=0;j<n-1-i;j++)if(strlen(s[i])>strlen(s[i+1])) strcpy(a,s[i]),strcpy(s[i],s[i+1]),strcpy(s[i+1],a);if(n%2==0){for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-3;i>0;i=i-2) printf("%s ",s[i]);}else{for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-1;i>0;i=i-2) printf("%s ",s[i]);}return 0;}27.The Ratio of gainers to losers #include<stdio.h>int main(){char s[5];int i,sum=0;gets(s);for(i=0;s[i]!='\0';i++){switch(s[i]){case'I': sum+=1;break; case'V': sum=5-sum;break; case'X':sum=10-sum;break; }}printf("%d\n",sum);return 0;}28.VOL大学乒乓球比赛#include <stdio.h>#include <stdlib.h>int main(){printf("A=Z\nB=X\nC=Y\n");return 0;}29.毕业设计论文打印#include <stdio.h>#include <stdlib.h>int main(){int a[100],j=1,i,n,m;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)if(a[i]>a[m]) j++;printf("%d",j++);return 0;}30.边沿与内芯的差#include <stdio.h>#include <stdlib.h>int main(){int A[100][100],i,j,m,n,s=0,t=0;scanf("%d%d",&n,&m);for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&A[i][j]);}}for(i=2;i<m;i++)s=s+A[1][i];for(i=2;i<m;i++)。

20.10月西工大《C语言程序设计》随机机考(答案)

20.10月西工大《C语言程序设计》随机机考(答案)

一、单选题(共35 道试题,共70 分)1. 若变量已正确定义,有以下程序段i=0; do printf("%d,",i);while(i++); printf("%d\n",i);其输出结果是()。

A.0,0B.0,1C.1,1D.程序进入无限循环正确答案:20269078972.{设有以下程序段int x=0,s=0; while(!x!=0) s+=++x; printf("%d",s); 则()。

A.运行程序段后输出0B.运行程序段后输出1C.程序段中的控制表达式是非法的D.程序段执行无限次3. 函数的功能是交换变量x和y中的值,且通过正确调用返回交换的结果。

能正确执行此功能的函数是()。

4. 对for(表达式1; ; 表达式3)可理解为()。

A.for(表达式1; 0;表达式3)B.for(表达式1: 1 ;表达式3)C.for(表达式1; 表达式1; 表达式3)D.for(表达式1; 表达式2; 表达式3)5. 以下描述错误的是()。

A.break语句不能用于循环语句和switch语句外的任何其他语句B.在switch语句中使用break语句或continue语句的作用相同C.在循环语句中使用continue语句是为了结束本次循环,而不是终止整个循环D.在循环语句中使用break语句是为了使流程跳出循环体,提前结束循环6. 以下叙述正确的是()。

A.do-while语句构成的循环不能用其它语句构成的循环来代替。

B.do-while语句构成的循环只能用break语句退出。

C.用do-while语句构成的循环,在while后的表达式为非零时结束循环。

D.用do-while语句构成的循环,在while后的表达式为零时结束循环。

7. 已知double *p[6]; 它的含义是()。

A.p是指向double类型变量的指针B.p是double类型数组C.p是指针数组D.p是数组指针8. C语言程度的基本单位是()。

西工大NOJ答案完全版

西工大NOJ答案完全版

输出A+B的结黑#i nclude<stdio.h>int main(){int a,b,sum;sca nf("%d%d",&a,&b);sum=a+b;prin tf("%d\n",sum); return 0; }#i nclude<stdio.h>#define PI 3.1415926int main(){double r,h,l,s,sq,vq,vz;sca nf("%lf%lf",&r,&h);l=2*PI*r;s=p|*r*r;sq=4*p|*r*r;vq=PI*r*r*r*4/3;vz=PI*r*r*h;prin tf("%.2lf\n%.2lf\n%.2lf\n%.2lf\n%.2lf\n",l,s,sq,vq,vz); return 0;}#i nclude<stdio.h>int main(){double ma,e ng,c,sum,ave;sca nf("%lf%lf%lf",&ma,&en g,&c); sum=ma+e ng+c; ave=sum/3;prin tf("%lf\n %lf\n",sum,ave); return 0;}#i nclude<stdio.h>int main(){int a,b,c,m;sca nf("%d%d%d",&a,&b,&c); if (a>b) m=a;else m=b;if (m<c) m=c;prin tf("%d",m);return 0;}#i nclude<stdio.h>int main(){int n;sca nf("%d",&n);if ((1000V n<10000)&&(n/1000==n%10)&&(n/100%10==n/10%10)) prin tf("y es\n");else if((100<n<=1000)&&(n/100==n%10)) printf("yes\n");else if((10< n <=100)&&(n/10==n%10)) pri ntf("yes\n");else if(0< n<=10) pri ntf("yes\n");else prin tf(" no\n");return 0;}#i nclude<stdio.h>int main(){double l,b on;sca nf("%lf",&l);if(|v=10) bon=1*0.1;else if(l<20) bo n=1+(l-10)*0.075; else if(l<40) bon=1.75+(1-20)*0.05; else if(l<60) bon=2.75+(1-40)*0.03; else if(l<100) bon=3.35+(1-60)*0.015; else bo n=3.95+(l-100)*0.01;prin tf("%lf\n",bo n);return 0;}输出为实型,帰留六惶小裁(单位为元)#i nclude<stdio.h>int main(){double d,m;sca nf("%lf",&d);if(d<=2) m=7;else if(d<=15){if(d-2==(i nt)(d-2)) m=7+(d-2)*1.5;else m=7+((i nt)(d-2)+1)*1.5;}else if(d-15==(int)(d-15)) m=26.5+(d-15)*2.1; else m=26.5+((i nt)(d-15)+1)*2.1;prin tf("%lf\n",m);return 0;}#i nclude<stdio.h>int main(){int y,m,d,Days,sum;sca nf("%d-%d-%d", &y,&m,&d);if((y%4==0&&y%100!=0)||(y%400==0)) Days=29; else Days=28; switch(m){case 1:sum=d;break;case 2:sum=31+d;break;case 3:sum=31+Days+d;break;case 4:sum=62+Days+d;break;case 5:sum=92+Days+d;break;case 6:sum=123+Days+d;break;case 7:sum=153+Days+d;break;case 8:sum=184+Days+d;break;case 9:sum=215+Days+d;break;case 10:sum=245+Days+d;break;case 11:sum=276+Days+d;break;case 12:sum=307+Days+d;break;}prin tf("%d\n",sum);return 0;}#i nclude<stdio.h>int main(){int i;sca nf("%d",&i);if(i>=90) prin tf("A\n");else if(i>=80) prin tf("B\n"); else if(i>=70) pri ntf("C\n"); else if(i>=60) prin tf("D\n"); else prin tf("E\n");return 0;}#i nclude<stdio.h>int main(){double x,y;sca nf("%lf,%lf", &x,&y);if((x-2)*(x-2)+(y-2)*(y-2)v=1) prin tf("10");else if((x-2)*(x-2)+(y+2)*(y+2)<=1) printf("10"); else if((x+2)*(x+2)+(y-2)*(y-2)<=1) printf("10"); else if((x+2)*(x+2)+(y+2)*(y+2)<=1) printf("10"); else prin tf("0");return 0;}输出根炬型・保留两性呷数.#i nclude<stdio.h>int main(){double l,x,r;sca nf("%lf %lf",&l,&r);while((2*l*l*l-4*l*l+3*l-6)!=0&&(2*r*r*r-4*r*r+3*r-6)!=0){ x=(l+r)/2;if((2*l*l*l-4*l*l+3*l-6)*(2*x*x*x-4*x*x+3*x-6)<=0)r=x;else l=x;}if(2*l*l*l-4*l*l+3*l-6==0) prin tf("%.2lf",l);else prin tf("%.2lf",r);return 0;}}#i nclude<stdio.h>#in clude<math.h>int main(){int i=800,t=2,c nt=0,sum=0;double e=-1;while(i>=500){while(t<=i-1){if(i%t==0) break;t++;}if(t==i) e=pow(-1,c nt),sum=sum+e*i,cnt++; i--;t=2;}prin tf("%d %d",cnt,sum);return 0;#i nclude<stdio.h>#in clude<math.h> int main(){int a=1;double b=1,pi=0,c=1;while(fabs(c)>=1e-6)pi=pi+c,b=b+2,a=-a,c=a/b; pi=pi*4; prin tf("%lf\n",pi); return 0;}}#i nclude<stdio.h>int main(){int a仁1,a2=1,n=2,sum=2,t; while(sum<=100){t=a1;a仁a2;a2=t+2*a2; sum=sum+a2;n++;}prin tf("%d\n", n-1);while(sum<=1000){t=a1;a仁a2;a2=t+2*a2; sum=sum+a2;n++;}prin tf("%d\n", n-1);while(sum<=10000){t=a1;a仁a2;a2=t+2*a2;}sum=sum+a2; n++;}prin tf("%d\n", n-1);}File Name :T01 Sxpp最次方数输出为整型.#i nclude<stdio.h>int main(){int x,a,s, n=1;scanf("%d %d",&x,&a);s=x;if(a!=O){for(; n<a;n++){s=s*x;if(s>=1000) s=s/100%10*100+s/10%10*10+s%10;}}prin tf("%d\n",s);return 0;輸出连腹奇蒙之和,格式如sa mple outputB示.#i nclude<stdio.h>int main(){int m, n,s;scan f("%d",&n);s=n*n*n;prin tf("%d*%d*%d=%d=" ,n,n,n ,s);for(m=1;s!=n*m;m++);if(n %2==1){for(s=-n/2;s< n/2;s++)pri ntf("%d+",m+2*s);prin tf("%d",m+n/2*2);}else{for(s=-n/2;s< n/2-1;s++)pri ntf("%d+",m+s*2+1); prin tf("%d",m+( n/2-1)*2+1);}}#i nclude<stdio.h>int main(){char a,b,c,x,y, z; a='A',b='B',c=C,x='X',y='Y',z='Z'; prin tf("%c=%c\n",a,z);prin tf("%c=%c\n",b,x);prin tf("%c=%c\n",c,y); return 0;}#i nclude<stdio.h>int main(){int a,b,t;sca nf("%d %d",&a,&b); if(a>b)t=a,a=b,b=t;for(;a<b;a++){ for(t=2;t<a;t++)if(a%t==0) break; if(t==a)pri ntf("%d ",a); }return 0;}#i nclude<stdio.h>int main(){int n=1;double a1= 1,a2=2,a3,sum=2; while( n<=19){a3=a1+a2;sum=sum+a3/a2;a仁a2;a2=a3;n++;}prin tf("%lf\n",sum);return 0;}}Input#i nclude<stdio.h>#in clude<math.h> int main() {double a;int n=0;sca nf("%lf",&a); a=fabs(a); if(a<=1)pri ntf("0\n"); else{while(a>1){ a=a/10;n++;}prin tf("%d\n", n);}#i nclude<stdio.h>int main(){int a=1,b=0,t, m,n=0; sca nf("%d", &t); while( n< t){ m=b; b=3*a+2*b;a=m;n++;}prin tf("%d %d",a,b); return 0;}}输出旅苣方法的数目#i nclude<stdio.h>#in clude<math.h> int main(){int n;int f(i nt n);sca nf("%d",&n);prin tf("%d\n",f( n));}int f(i nt n){int a;if(n==1|| n==2)a=0;else if(n==3)a=1;else if(n==4)a=3;elsea=f( n-1)*2+pow(2, n-4)-f( n-4); return a; }#i nclude<stdio.h>int main(){int n ,x=1234,y=1,a,b,c,d,e,f,g,h,i,j;sca nf("%d",&n);for(;x<49383&&y<98765;x++){y=x* n;a=x/10000%10; b=x/1000%10;c=x/100%10; d=x/10%10;e=x%10;f=y/10000%10; g=y/1000%10;h=y/100%10;i=y/10%10;j=y%10; if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==j) con ti nue;if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==j) con ti nue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==j) con ti nue;if(d==e||d==f||d==g||d==h||d==i||d==j) con ti nue; if(e==f||e==g||e==h||e==i||e==j) con ti nue; if(f==g||f==h||f==i||f==j) con ti nue;if(g==h||g==i||g==j) continue;if(h==i||h==j) continue;if(i==j) continue;prin tf("%05d/%05d=%d\n",y,x, n); }return 0;}1 1 1/+(科十iy + +歹輪出计算绪果,赧鈕5粒小薮.#i nclude<stdio.h>#i nclude<stdlib.h>#in clude<math.h> int main(){in t m,n ,i;double x,s=0;sca nf("%d%d",&n,&m);for(i=n ;i<=m;i++){x=pow(i,2.0); s=s+1/x;}prin tf("%.5lf\n",s); return 0;}#i nclude<stdio.h>int main(){int x,y,a,b,L;double t;scan f("%d%d%d%d%d", &x, &y,&a,&b,&L); if(a==b) prin tf("impossible\n");else if(x>y){ if(a>b)y=L-x+y,t=(double)y/(a-b); else y=x-y,t=(double)y/(b-a);if((i nt)t==t)pri ntf("%d\n",(i nt)t); else prin tf("%lf\n",t);}else { if(a>b)y=y-x,t=(double)y/(a-b); else y=L-y+x,t=(double)y/(b-a); if((i nt)t==t)pri ntf("%d\n",(i nt)t); else prin tf("%lf\n",t);}return 0;}#i nclude<stdio.h>int _max(i nt a,i nt b){ _retur n a>b?a:b;}int a[20];int f[20][20];int main(){int n ,i,j,s=0;sca nf("%d",&n);for(i=0;i< n;i++)scan f("%d",&a[i]);for(j=1;j< n;j++)f[0][0]=a[0],f[0][j]=f[0][j-1]*a[j]; for(i=1;i< n;i++){f[i][i-1]=1;for(j=i;j< n;j++)f[i][j]=f[i][j-1]*a[j];}for(i=0;i< n;i++) for(j=i;j< n;j++) s=_max(s,f[i][j]);if(s==O)pri ntf("-1\n"); else prin tf("%d\n",s); return 0;}#i nclude<stdio.h>int main(){int x=192,y, z,a,b,c,d,e,f,g,h,i;for(;x<328;x++){y=2*x;z=3*x;a=x/100%10;b=x/10%10;c=x%10;d=y/100%10;e=y/10%10;f=y%10;g=z/100%10;h=z/10%10;i=z%10;if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==0) con ti nue;if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==0) con ti nue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==0) con ti nue;if(d==e||d==f||d==g||d==h||d==i||d==0) con ti nue;if(e==f||e==g||e==h||e==i||e==O) con ti nue; if(f==g||f==h||f==i||f==O) con ti nue; if(g==h||g==i||g==O) con ti nue; if(h==i||h==O) continue;prin tf("%d %d %d\n",x,y,z);}return 0;}#i nclude<stdio.h>int main(){int a,b,c,sum=10;sca nf("%d%d%d",&a,&b,&c);for(;sum<=100;sum++){if(sum%3==a&&sum%5==b&&sum%7==c){ prin tf("%d\n",sum); break;}}if(sum==101)pri ntf("-1\n");return 0;}輸出合敎世圮起始导殆束年檢,用空恪隔开#i nclude<stdio.h>#in clude<math.h>int main(){int ce,y,m, n,a=0;sca nf("%d",&n); for(ce=0;;ce+=100){for(y=ce+1;y<ce+100;y+=2){ for(m=3;m<sqrt(y);m+=2){ if(y%m==0) break;}if(m>=sqrt(y)) break;}if(y==ce+101) a++;if(a==n) break;}prin tf("%d %d\n",ce,ce+99); return 0;}{int n,i;sca nf("%d",&n);for(i=1;i<=n ;i++){if(i%7==0) pri ntf("%d ",i);else if(i/1000%10==7||i/100%10==7||i/10%10==7||i%10==7) printf("%d ",i ); }return 0;}#i nclude<stdio.h>double a[100000000];int main(){int n,i;double ave,sum=0;sca nf("%d",&n);for(i=0;i< n;i++){scan f("%lf",&a[i]); sum=sum+a[i];}ave=su m/n;for(i=0,sum=0;i <n ;i++) sum=sum+(a[i]-ave)*(a[i]-ave); prin tf("%lf\n",sum); return 0;}int f[100000000];int main(){int n,i;sca nf("%d",&n);for(i=0;i< n;i++){int a,b;scan f("%d%d",&a,&b);f[i]=a+b;}for(i=0;i< n;i++){if(f[i]>100) f[i]=f[i]/10%10*10+f[i]%10,pri ntf("%d\n",f[i]); else prin tf("%d\n",f[i]); }return 0;}ttinc-udeAsfdio.hvttinc-udeAmafh.hvinfn H n v v k t八「efumn QO —k八inf main。

西工大C语言POJ习题答案

西工大C语言POJ习题答案

一.1.第一季10题全(注:第五题问题已经解决,确认AC!)之勘阻及广创作#include <stdio.h>int main(){int a,b,sum;scanf("%d%d",&a,&b);sum=a+b;printf("%d\n",sum);return 0;}2.#include <stdio.h>#define PI 3.1415926int main(){double r,h,l,s,sq,vq,vz;scanf("%lf%lf",&r,&h);l=2*PI*r;s=PI*r*r;sq=4*PI*r*r;vq=4*PI*r*r*r/3;vz=s*h;printf("%.2lf\n%.2lf\n%.2lf\n%.2lf\n%.2lf\n",l,s,sq,v q,vz); return 0;}3.#include <stdio.h>int main(){int a,b,c;double d,e;scanf("%d%d%d",&a,&b,&c);d=a+b+c;e=d/3;printf("%lf\n%lf\n",d,e);}4.#include <stdio.h>int main(){int a,b,c;scanf("%d%d%d",&a,&b,&c);if(a<b)a=b;if(a<c)a=c;printf("%d\n",a);}5.#include<stdio.h>int main(){int i=0,j=0,k=1;char a[6];while((a[i]=getchar())!='\n'){ i++;}for(;i>0;i--){if(a[j]==a[i-1]){j++;continue;}else {k=0;break;}}if(k==1)printf("yes\n");elseprintf("no\n"); }6.#include<stdio.h>int main(){double a,c;scanf("%lf",&a);switch((int)a/10) {case 0:c=a*0.1;break;case 1:c=(a-10)*0.075+10*0.1;break;case 2:case 3:c=(a-20)*0.05+10*0.075+10*0.1;break;case 4: case 5:c=(a-40)*0.03+20*0.05+10*0.075+10*0.1;break;case 6:case 7:case 8:case 9:c=(a-60)*0.015+20*0.03+20*0.05+10*0.075+10*0.1;break;default:c=(a-100)*0.01+40*0.015+20*0.03+20*0.05+10*0.075+10*0.1;}printf("%lf\n",c);return 0;}7.#include<stdio.h>int main(){double a,b,c;scanf("%lf",&a);c=(int)a;if(a>c)a=c+1;if(a>15)b=(a-15)*2.1+7+13*1.5;else {if(a>2)b=(a-2)*1.5+7;else b=7; } printf("%lf\n",b);return 0;}8.#include <stdio.h>int main(){int a,b,c,e,f=30,g=31,n;scanf("%d-%d-%d",&a,&b,&c);if((a%400==0)||(a%100!=0&&a%4==0))e=29;elsee=28;switch (b){case 1:n=c;break;case 2:n=g+c;break;case 3:n=g+e+c;break; case 4:n=g+e+g+c;break;case 5:n=g+e+g+f+c;break;case 6:n=g+e+g+f+g+c;break;case 7:n=g+e+g+f+g+f+c;break;case 8:n=g+e+g+f+g+f+g+c;break;case 9:n=g+e+g+f+g+f+g+g+c;break;case 10:n=g+e+g+f+g+f+g+g+f+c;break;case 11:n=g+e+g+f+g+f+g+g+f+g+c;break;default: n=g+e+g+f+g+f+g+g+f+g+f+c;}printf("%d\n",n);return 0;}9.#include <stdio.h>int main(){int x;scanf("%d",&x);if(x>=90&&x<=100)printf("A\n");else if (x>=80)printf("B\n");else if (x>=70)printf("C\n");else if (x>=60)printf("D\n");elseprintf("E\n");return 0;}10.#include<stdio.h>int main(){double x,y,s;scanf("%lf,%lf",&x,&y);s=(x+2)*(x+2)+(y-2)*(y-2);if(s>1){s=(x+2)*(x+2)+(y+2)*(y+2);if(s>1){ s=(x-2)*(x-2)+(y+2)*(y+2);if(s>1){s=(x-2)*(x-2)+(y-2)*(y-2);if(s>1){printf("0\n");return 1;}}}}printf("10\n");return 0;}二。

西工大NOJ答案完全版

西工大NOJ答案完全版

#include<stdio.h>int main(){int a,b,sum;scanf("%d%d",&a,&b); sum=a+b;printf("%d\n",sum);return 0;}#include<stdio.h>#define PI 3.1415926int main(){double r,h,l,s,sq,vq,vz;scanf("%lf%lf",&r,&h);l=2*PI*r;s=PI*r*r;sq=4*PI*r*r;vq=PI*r*r*r*4/3;vz=PI*r*r*h;printf("%.2lf\n%.2lf\n%.2lf\n%.2lf\n%.2lf\n",l,s,sq,vq,vz); return 0;}#include<stdio.h>int main(){double ma,eng,c,sum,ave;scanf("%lf%lf%lf",&ma,&eng,&c); sum=ma+eng+c;ave=sum/3;printf("%lf\n%lf\n",sum,ave);return 0;}#include<stdio.h>int main(){int a,b,c,m;scanf("%d%d%d",&a,&b,&c); if (a>b) m=a;else m=b;if (m<c) m=c;printf("%d",m);return 0;}#include<stdio.h>int main(){int n;scanf("%d",&n);if ((1000<n<10000)&&(n/1000==n%10)&&(n/100%10==n/10%10)) printf("y es\n");else if((100<n<=1000)&&(n/100==n%10)) printf("yes\n");else if((10<n<=100)&&(n/10==n%10)) printf("yes\n");else if(0<n<=10) printf("yes\n");else printf("no\n");return 0;}#include<stdio.h>int main(){double l,bon;scanf("%lf",&l);if(l<=10) bon=l*0.1;else if(l<20) bon=1+(l-10)*0.075;else if(l<40) bon=1.75+(l-20)*0.05; else if(l<60) bon=2.75+(l-40)*0.03; else if(l<100) bon=3.35+(l-60)*0.015; else bon=3.95+(l-100)*0.01;printf("%lf\n",bon);return 0;}#include<stdio.h>int main(){double d,m;scanf("%lf",&d);if(d<=2) m=7;else if(d<=15){if(d-2==(int)(d-2)) m=7+(d-2)*1.5;else m=7+((int)(d-2)+1)*1.5;}else if(d-15==(int)(d-15)) m=26.5+(d-15)*2.1; else m=26.5+((int)(d-15)+1)*2.1;printf("%lf\n",m);return 0;}#include<stdio.h>int main(){int y,m,d,Days,sum;scanf("%d-%d-%d",&y,&m,&d);if((y%4==0&&y%100!=0)||(y%400==0)) Days=29; else Days=28;switch(m){case 1:sum=d;break;case 2:sum=31+d;break;case 3:sum=31+Days+d;break;case 4:sum=62+Days+d;break;case 5:sum=92+Days+d;break;case 6:sum=123+Days+d;break;case 7:sum=153+Days+d;break;case 8:sum=184+Days+d;break;case 9:sum=215+Days+d;break;case 10:sum=245+Days+d;break;case 11:sum=276+Days+d;break;case 12:sum=307+Days+d;break;}printf("%d\n",sum);return 0;}#include<stdio.h>int main(){int i;scanf("%d",&i);if(i>=90) printf("A\n");else if(i>=80) printf("B\n"); else if(i>=70) printf("C\n"); else if(i>=60) printf("D\n"); else printf("E\n");return 0;}#include<stdio.h>int main(){double x,y;scanf("%lf,%lf",&x,&y);if((x-2)*(x-2)+(y-2)*(y-2)<=1) printf("10");else if((x-2)*(x-2)+(y+2)*(y+2)<=1) printf("10"); else if((x+2)*(x+2)+(y-2)*(y-2)<=1) printf("10"); else if((x+2)*(x+2)+(y+2)*(y+2)<=1) printf("10"); else printf("0");return 0;}#include<stdio.h>int main(){double l,x,r;scanf("%lf %lf",&l,&r);while((2*l*l*l-4*l*l+3*l-6)!=0&&(2*r*r*r-4*r*r+3*r-6)!=0){ x=(l+r)/2;if((2*l*l*l-4*l*l+3*l-6)*(2*x*x*x-4*x*x+3*x-6)<=0)r=x;else l=x;}if(2*l*l*l-4*l*l+3*l-6==0) printf("%.2lf",l);else printf("%.2lf",r);return 0;}#include<stdio.h>#include<math.h>int main(){int i=800,t=2,cnt=0,sum=0;double e=-1;while(i>=500){while(t<=i-1){if(i%t==0) break;t++;}if(t==i) e=pow(-1,cnt),sum=sum+e*i,cnt++; i--;t=2;}printf("%d %d",cnt,sum);return 0;}#include<stdio.h>#include<math.h>int main(){int a=1;double b=1,pi=0,c=1;while(fabs(c)>=1e-6)pi=pi+c,b=b+2,a=-a,c=a/b; pi=pi*4;printf("%lf\n",pi);return 0;}#include<stdio.h>int main(){int a1=1,a2=1,n=2,sum=2,t; while(sum<=100){t=a1;a1=a2;a2=t+2*a2;sum=sum+a2;n++;}printf("%d\n",n-1);while(sum<=1000){t=a1;a1=a2;a2=t+2*a2;sum=sum+a2;n++;}printf("%d\n",n-1);while(sum<=10000){t=a1;a1=a2;a2=t+2*a2;sum=sum+a2;n++;}printf("%d\n",n-1);}#include<stdio.h>int main(){int x,a,s,n=1;scanf("%d %d",&x,&a);s=x;if(a!=0){for(;n<a;n++){s=s*x;if(s>=1000) s=s/100%10*100+s/10%10*10+s%10; }}printf("%d\n",s);return 0;}#include<stdio.h>int main(){int m,n,s;scanf("%d",&n);s=n*n*n;printf("%d*%d*%d=%d=",n,n,n,s);for(m=1;s!=n*m;m++);if(n%2==1){for(s=-n/2;s<n/2;s++)printf("%d+",m+2*s);printf("%d",m+n/2*2);}else{for(s=-n/2;s<n/2-1;s++)printf("%d+",m+s*2+1); printf("%d",m+(n/2-1)*2+1);}return 0;}#include<stdio.h>int main(){char a,b,c,x,y,z;a='A',b='B',c='C',x='X',y='Y',z='Z'; printf("%c=%c\n",a,z);printf("%c=%c\n",b,x);printf("%c=%c\n",c,y);return 0;}#include<stdio.h>int main(){int a,b,t;scanf("%d %d",&a,&b);if(a>b)t=a,a=b,b=t;for(;a<b;a++){for(t=2;t<a;t++)if(a%t==0) break; if(t==a)printf("%d ",a);}return 0;}#include<stdio.h>int main(){int n=1;double a1=1,a2=2,a3,sum=2; while(n<=19){a3=a1+a2;sum=sum+a3/a2;a1=a2;a2=a3;n++;}printf("%lf\n",sum);return 0;}#include<stdio.h>#include<math.h>int main(){double a;int n=0;scanf("%lf",&a);a=fabs(a);if(a<=1)printf("0\n"); else{while(a>1){a=a/10;n++;}printf("%d\n",n); }return 0;}#include<stdio.h>int main(){int a=1,b=0,t,m,n=0; scanf("%d",&t);while(n<t){m=b;b=3*a+2*b;a=m;n++;}printf("%d %d",a,b); return 0;}#include<stdio.h>#include<math.h>int main(){int n;int f(int n);scanf("%d",&n);printf("%d\n",f(n));}int f(int n){int a;if(n==1||n==2)a=0;else if(n==3)a=1;else if(n==4)a=3;elsea=f(n-1)*2+pow(2,n-4)-f(n-4); return a;}#include<stdio.h>int main(){int n,x=1234,y=1,a,b,c,d,e,f,g,h,i,j;scanf("%d",&n);for(;x<49383&&y<98765;x++){y=x*n;a=x/10000%10;b=x/1000%10;c=x/100%10;d=x/10%10;e=x%10;f=y/10000%10;g=y/1000%10;h=y/100%10;i=y/10%10;j=y%10;if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==j) continue; if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==j) continue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==j) continue;if(d==e||d==f||d==g||d==h||d==i||d==j) continue;if(e==f||e==g||e==h||e==i||e==j) continue;if(f==g||f==h||f==i||f==j) continue;if(g==h||g==i||g==j) continue;if(h==i||h==j) continue;if(i==j) continue;printf("%05d/%05d=%d\n",y,x,n); }return 0;}#include<stdio.h>#include<stdlib.h>#include<math.h>int main(){int m,n,i;double x,s=0;scanf("%d%d",&n,&m);for(i=n;i<=m;i++){x=pow(i,2.0);s=s+1/x;}printf("%.5lf\n",s);return 0;}#include<stdio.h>int main(){int x,y,a,b,L;double t;scanf("%d%d%d%d%d",&x,&y,&a,&b,&L); if(a==b) printf("impossible\n");else if(x>y){if(a>b)y=L-x+y,t=(double)y/(a-b);else y=x-y,t=(double)y/(b-a);if((int)t==t)printf("%d\n",(int)t);else printf("%lf\n",t);}else {if(a>b)y=y-x,t=(double)y/(a-b);else y=L-y+x,t=(double)y/(b-a);if((int)t==t)printf("%d\n",(int)t);else printf("%lf\n",t);}return 0;}#include<stdio.h>int _max(int a,int b){return a>b?a:b;}int a[20];int f[20][20];int main(){int n,i,j,s=0;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);for(j=1;j<n;j++)f[0][0]=a[0],f[0][j]=f[0][j-1]*a[j]; for(i=1;i<n;i++){f[i][i-1]=1;for(j=i;j<n;j++)f[i][j]=f[i][j-1]*a[j];}for(i=0;i<n;i++)for(j=i;j<n;j++)s=_max(s,f[i][j]);if(s==0)printf("-1\n");else printf("%d\n",s);return 0;}#include<stdio.h>int main(){int x=192,y,z,a,b,c,d,e,f,g,h,i;for(;x<328;x++){y=2*x;z=3*x;a=x/100%10;b=x/10%10;c=x%10;d=y/100%10;e=y/10%10;f=y%10;g=z/100%10;h=z/10%10;i=z%10;if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==0) continue; if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==0) continue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==0) continue;if(d==e||d==f||d==g||d==h||d==i||d==0) continue;if(e==f||e==g||e==h||e==i||e==0) continue;if(f==g||f==h||f==i||f==0) continue;if(g==h||g==i||g==0) continue;if(h==i||h==0) continue;printf("%d %d %d\n",x,y,z);}return 0;}#include<stdio.h>int main(){int a,b,c,sum=10;scanf("%d%d%d",&a,&b,&c);for(;sum<=100;sum++){if(sum%3==a&&sum%5==b&&sum%7==c){ printf("%d\n",sum); break;}}if(sum==101)printf("-1\n");return 0;}#include<stdio.h>#include<math.h>int main(){int ce,y,m,n,a=0;scanf("%d",&n);for(ce=0;;ce+=100){for(y=ce+1;y<ce+100;y+=2){ for(m=3;m<sqrt(y);m+=2){ if(y%m==0) break;}if(m>=sqrt(y)) break;}if(y==ce+101) a++;if(a==n) break;}printf("%d %d\n",ce,ce+99); return 0;}#include<stdio.h>int main(){int n,i;scanf("%d",&n);for(i=1;i<=n;i++){if(i%7==0) printf("%d ",i);else if(i/1000%10==7||i/100%10==7||i/10%10==7||i%10==7) printf("%d ",i );}return 0;}#include<stdio.h>double a[100000000];int main(){int n,i;double ave,sum=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%lf",&a[i]);sum=sum+a[i];}ave=sum/n;for(i=0,sum=0;i<n;i++)sum=sum+(a[i]-ave)*(a[i]-ave); printf("%lf\n",sum);return 0;}#include<stdio.h>int f[100000000];int main(){int n,i;scanf("%d",&n);for(i=0;i<n;i++){int a,b;scanf("%d%d",&a,&b);f[i]=a+b;}for(i=0;i<n;i++){if(f[i]>100) f[i]=f[i]/10%10*10+f[i]%10,printf("%d\n",f[i]); else printf("%d\n",f[i]);}return 0;}#include<stdio.h>#include<math.h>int getbit(int n,int k){n=n>>k-1;return n&1;}int main(){int n,k;scanf("%d%d",&n,&k); printf("%d",getbit(n,k)); return 0;}#include<stdio.h>int _min(int n){int i=0;if(n>=100) i=n/100%10,n=n/10%10*10+n%10; if(n>=50) i+=1,n-=50;if(n>=10) i+=n/10%10,n%=10;if(n>=5) i+=1,n-=5;if(n>=2) i+=n/2,n%=2;if(n==1) i+=1;return i;}int f[100];int main(){int n,i,sum;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&f[i]);for(sum=0,i=0;i<n;i++)sum=sum+_min(f[i]);printf("%d\n",sum);return 0;}#include<stdio.h>int fceil(double x){if(x>0){if((int)x==x) return x; else return (int)x+1; }else return (int)x;}int main(){double x;scanf("%lf",&x);printf("%d\n",fceil(x)); return 0;}#include<stdio.h>int _move(int value,int n){int t;if(n>0)t=value>>n|value<<32-n;else {n=-n;t=value<<n|value>>32-n;}return t;}int main(){int value,n;scanf("%d%d",&value,&n);printf("%d\n",_move(value,n)); return 0;}#include<stdio.h>void timesum(int AH,int AM,int AS,int BH,int BM,int BS){int h=0,m=0,s=0;if(AS+BS>59) s=(AS+BS)-60,m++;else s=AS+BS;if(AM+BM>59) m+=((AM+BM)-60),h++;else m=AM+BM;h+=(AH+BH);printf("%d %d %d\n",h,m,s);}int main(){int AH,AM,AS,BH,BM,BS;scanf("%d%d%d%d%d%d",&AH,&AM,&AS,&BH,&BM,&BS); timesum(AH,AM,AS,BH,BM,BS);return 0;}#include<stdio.h> void f(long int n) {int m;m=n%10;printf("%d",m); n/=10;if(n!=0) f(n);}int main(){long int n;scanf("%d",&n); f(n);return 0;}#include<stdio.h>int getfloor(double x){if(x>0) return (int)x;else return (int)x-1;}int main(){double x;scanf("%lf",&x);printf("%d\n",getfloor(x)); return 0;}#include<stdio.h>inline int xchg(unsigned char n) {n=n>>4|n<<4;return n;}int main(){unsigned char n;scanf("%d",&n);printf("%d\n",xchg(n));return 0;}#include<stdio.h>void QuickSort(int A[100],int s,int m) {int i,t;for(;s<=m;s++){for(i=s;i<=m;i++)if(A[s]<A[i]){t=A[s];A[s]=A[i];A[i]=t;}printf("%d ",A[s]);}}int main(){int s,m,n,i,A[100];scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&m);for(i=0;i<s;i++)printf("%d ",A[i]);QuickSort(A,s,m);for(i=m+1;i<n;i++)printf("%d ",A[i]);return 0;}#include<stdio.h>double avg(int A[100],int s,int e) {double sum;for(sum=0;s<=e;s++)sum=sum+A[s];return sum;}int main(){int A[100],s,e,i,n;double a;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&e);a=avg(A,s,e)/(e-s+1);printf("%lf\n",a);return 0;}#include<stdio.h>int main(){int n,a[100],i,j,s=0,t=0; scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n-1;i++)for(j=i+1;j<n;j++){if(a[i]>a[j]) s++;else if(a[i]<a[j]) t++; }s=s>t?t:s;printf("%d\n",s);return 0;}#include<stdio.h>void SelectionSort(int A[],int s,int m) {int i,t,n;for(n=s;n<=s+m-1;n++){for(i=n;i<=s+m-1;i++)if(A[n]<A[i]){t=A[n];A[n]=A[i];A[i]=t;}printf("%d ",A[n]);}}int main(){int s,m,n,i,A[100];scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&m);for(i=0;i<s;i++)SelectionSort(A,s,m);for(i=m+1;i<n;i++)printf("%d ",A[i]);return 0;}#include<stdio.h>void SelectionSort(int A[],int s,int m) {int i,t,n;for(n=s;n<=s+m-1;n++){for(i=n;i<=s+m-1;i++)if(A[n]<A[i]){t=A[n];A[n]=A[i];A[i]=t;}printf("%d ",A[n]);}}int main(){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&m); for(i=0;i<s;i++)printf("%d ",A[i]);SelectionSort(A,s,m); for(i=m+1;i<n;i++)printf("%d ",A[i]);return 0;}#include<stdio.h>int main(){int a[100][100],n,i,j;scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]); for(i=0;i<n;i++)for(j=0;j<n;j++){if(j<n-i-1) printf(" ");else printf("%d ",a[i][j]); if(j==n-1) printf("\n");}return 0;}#include<stdio.h>int main(){int a[100][100],n,i,j;scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]); for(i=0;i<n;i++)for(j=0;j<n;j++){if(j<i) printf(" ");else printf("%d ",a[i][j]); if(j==n-1) printf("\n");}return 0;}#include<stdio.h>int main(){int a[100][100],n,i,j;scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]); for(i=0;i<n;i++)for(j=0;j<n;j++){if(j>n-i-1) printf(" ");else printf("%d ",a[i][j]); if(j==n-1) printf("\n");}return 0;}#include<stdio.h>int main(){int a[100][100],n,m,i,j,s1,s2; scanf("%d%d",&n,&m);for(i=0;i<n;i++)for(j=0;j<m;j++)scanf("%d",&a[i][j]);for(j=0,s1=0;j<m;j++)s1=s1+a[0][j]+a[n-1][j];for(i=1,s2=0;i<n-1;i++){s1=s1+a[i][0]+a[i][m-1];for(j=1;j<m-1;j++)s2=s2+a[i][j];}printf("%d\n",s1-s2);return 0;}#include<stdio.h>int main(){int a[100],b[100],i,j,n; scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]); b[i]=a[i];}for(i=1;i<n;i+=2)printf("%d ",b[i]);return 0;}。

西工大2021年4月机考《C语言程序设计》作业参考答案

西工大2021年4月机考《C语言程序设计》作业参考答案

西工大2021年4月机考《C语言程序设计》作业参考答案试卷总分:100 得分:100本科目3次作答机会,每次试题内容相同,只是题目和选项顺序是随机调整的,大家可放心下载使用一、单选题(共35 道试题,共70 分)1. 以下错误的描述为()。

A.在函数之外定义的变量称为外部变量,外部变量是全局变量B.在一个函数中既可以使用本函数中的局部变量,又可以使用外部变量C.外部变量定义和外部变量声明的含义相同D.若在同一个源文件中,外部变量与局部变量同名,则在局部变量的作用范围内,外部变量不起作用正确答案:C2. 有以下程序#includemain(){ int x=1,y=0,a=0,b=0;switch(x){ case 1:switch(y){ case 0:a++; break;case 1:b++; break;}case 2:a++; b++; break;case 3:a++; b++;}printf("a=%d,b=%d\n",a,b);}A.a=1,b=0B.a=2,b=2C.a=1,b=1D.a=2,b=1正确答案:D3. 以下叙述中错误的是()。

A.计算机不能直接执行用C语言编写的源程序B.C程序经C编译程序编译后,生成后缀为.obj的文件是一个二进制文件C.后缀为.obj的文件,经连接程序生成后缀为.exe的文件是一个二进制文件D.后缀为.obj和.exe的二进制文件都可以直接运行正确答案:D4. 若二维数组a由m列,则在a[i][j]之前的元素个数为()。

A.j*m+iB.i*m+jC.i*m+j-1D.i*m+j+1正确答案:B5. 有以下程序main(){ int i,s=1;for (i=1;i<50;i++)if(!(i%5)&&!(i%3)) s+=i;printf("%d\n",s);A.409B.277C.1D.91正确答案:D6. 若a为int类型,且其值为5,则执行表达式a+=a-=a*a后,a的值是()。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档