西工大C语言POJ习题答案.docx

上传人:文*** 文档编号:68221779 上传时间:2022-12-27 格式:DOCX 页数:130 大小:100.33KB
返回 下载 相关 举报
西工大C语言POJ习题答案.docx_第1页
第1页 / 共130页
西工大C语言POJ习题答案.docx_第2页
第2页 / 共130页
点击查看更多>>
资源描述

《西工大C语言POJ习题答案.docx》由会员分享,可在线阅读,更多相关《西工大C语言POJ习题答案.docx(130页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、一.1.第一季10题全(注:第五题问题已经解决,确认AC!)#include i nt ma i n 0(i nt a, b, sum;scanf (1,%d%d,&af &b);sum=a+b;pr i ntf (%dn, sum);return 0;2.#i nclude #defi ne PI i nt ma i n ()doub I e r, h, I, s, sq, vq, vz;scanf;l=2*PI*r;s=PI*r*r;sq=4*PI*r*r;vq=4*PI*r*r*r/3;vz=s*h;pri ntf (%.21 fn%.21 fn%,21 fn%.2 I fn%.21 f

2、n, I, s, sq, vq, vz);return 0;3.#include i nt ma i n 01 nt a, b, c;doub I e d( e;scanf (%d%d%d,&a,&b,&c);d=a+b+c;e=d/3;pr i ntf (% I fn% I fn, d, e); return 0;# i ncIude i nt ma i n ()i nt a, b, c;scanf (%d%d%dn,&a,&b,&c); i f (ab)a二b;i f (ac)a=c;pr i ntf (%drT,a);return 0;)#includei nt ma i n ()int

3、 i=0, j=0, k=1;char a6;wh i le(ai=getchar ()!=n)(i+;)for (;i 0;i-)if(3jai1)j+;cont i nue;eIse k=0;break;)if(k=1)pr i ntf (yesn);e I sepr i ntf (non);6.# i ncIudei nt ma i n ()(doub I e a, c;scanf (%lf,&a);switch (i nt)a/10)(case 0:c=a*;break;case 1:c=(a-10)*+10*;bre ak;case 2:case 3:c=(a-20)*+10*+10

4、*;break;case 4:case 5:c=(a-40)*+20*+10*+10*;break;case 6:case 7:case 8:case 9:c=(a-60)*+20*+20*+10*+10*;break;defau11:c=(a-100)*+40*+20*+20*+10*+10*;)pr i ntf (%lfn, c);return 0;)7.# i ncIude i nt ma i n ()(doub I e a, b, c;scanf (%lf,&a);c=(i nt)a;i f(ac)a=c+1;if (a15)b=(a-15)*+7+13*; e I se if (a2

5、)b=(a-2)*+7;eIse b=7;)pr i ntf (% I fn, b);return 0;#include i nt ma i n ()(i nt a, b, c, e, f=30, g=31, n;scanf (”d-%d-%d”,&a,&b,&c);i f(a%400=0)|(a%100!=0&a%4=0)e=29;e I see=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

6、: rFg+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;br eak;case 11:n=g+e+g+f+g+f+g+g+f+g+c; break;defauIt: n=g+e+g+f+g+f+g+g+f+g+f +c;1pr i ntf (%dn, n);return 0;#include i nt ma i n ()(i nt x;scanf (%d,&x);

7、if (x=90&x=80)printf (Bn); elseif(x=70)pr i ntf(Cn);eIsei f(x=60)pr intf(Dn);e I seprintf(En);return 0;9.#includei nt ma i n 0(doub I e x, y, s;scanf&y);s=(x+2)*(x+2)+(y-2)*(y-2);if (s1)s=(x+2)*(x+2)+(y+2)*(y+2);if (s1)s-(x-2)*(x-2)+(y+2)*(y+2);if (s1)s-(x-2)*(x-2)+(y-2)*( y-2);if (s1)printf (0n);re

8、turn 1;)printf (lOXn); return 0;)二第二季15题全10.#include i nt ma i n ()(int x=0, a=0, c=0, i=1; scanf (%d%d,&x,&a);c=x;for(i=1;ia;i-H-)c=(c*x)%1000;);if (c100)if (c=100) pr intf(%dnf c);return 0;11.#include i nt ma i n ()int i=1, a=0, b=0, c=1016, k=1;for(;k=1;)c=c+4;a=c;b=c;for(i=1;i=4;i+) a=a/4*5+1;if

9、(a%4!=0)k=0;;);1;a=a/4*5+1;if (k=1)pr i ntf (%d %dn,a, b); break;;1;return 0;)13oo#include#inc ludeO i nt ma i n ()int i=1t n=0, b=0;double j=0, k=0, m=0;scanf (%dn,&n);for (;i=n;i+)b=i%2-1;k=pow (-1, b);m=pow(2, i);j+=k*m/(m-k)/(2*m+k);;pr i ntf (%.6lfn j);return 0;14.#include#include i nt ma i n (

10、)(int a=0,b=0, i=0, t;scanf (%d%d,&a,&b);if (ab)t=a;a=b;b=t; for (;a=b;a+) int m=1;for(i=2;i=sqrt (a);i +) if (a%i=0)m=0;break;1if (m=1)pr intf(n%d , a);1printf (nn); return 0;15.#include#include i nt ma i n ()int a=0,b=0, c=0; scanf (%d,&a);b=(i nt) pow (a,2);c=(i nt) pow (a,3);if (a%2) printf (%d*

11、%d*%d=%d=%d”,a, a, a, c, b-a/2*2);int n=1;for(;na;n+)printf(+%d, b-a/2*2+2*n);)printf (nn););if (a%2=0)(int n=1;printf (%d*%d*%d=%d=%d,a, a, a, c, b+1-a);for (;na;n+)pr i ntf (+%d, b+1-a+n*2);)printf CAn);;return 0;#include#includei nt ma i n ()(int a=0, b=0, c=0, d=0, e=0, x=0, y=0, z=0, u=0, v=0;d

12、oubIe f=0;for (a=0;a=2;a+)doubIe m=0;for(b=0;b=(20-8*a)/5;b+)for (c=0;c=(20-8*a-5*b)/3;c+)for (d=0;d=(20-8*a-5*b-3*c)/2;d+)e=20-8*a-5*b-3*c-2*d;m=2000*pow (1+*12*8, a)*pow (1+*12*5, b)*pow (1+*12*3, c)*pow (1+*12*2, d)*pow (1+*12, e)rif (fm) f=m;x二a, y=b, z=c, u=d, v=e;;):1:);pr intf (%d %d %d %d %d

13、n%.2lfn, xf y, z, u, v, f);return 0;17.#include#include i nt ma i n ()(doubIe a=0;int i=0, b=0;scanf (%lfn,&a);b 二(int) a;for (;(int)(b/pow(10, i);) i+;printf (,%dn, i);return 0;18o#include i nt ma i n () doubIe a=1, b=2, i=1, m=0; for (;i=20;i+)(m+=b/a;b=a+b; a=b-a;)pr i ntf (n%.6lfn, m); return 0;

14、)19.#include#incIude i nt ma i n ()doubIe a=0, b=0, c=0, e=0;scanf (r,%lf%lfn,&a,&b);for(;b-a;)c=2*pow (a,3)-4*pow (aT 2)+3*a-6;e=2*pow(a+b)/2,3)-4*pow(a+b)/2,2)+3*(a+b)/2-6;if (c*e=0)if (e=0)a=(a+b)/2;break;);if (c*e!=0)if (c*e0)b=(a+b)/2;e I sea=(a+b)/2;1;printfC%.2lfn,a);return 0;20.# i ncIudei n

15、t ma i n ()char i,j,k;for(i=X ;i=Z ;i+)for (户 if(i!=j) for (k=X;kZ;k+)if (i!=k&j!=k)if (k!=X,)&(k!=Z)&(i !=X) printf(A=%cnB=%cnC=%cn, i, j, k);return 0;)21.i nt ma i n ()i nt a, b, i, j, ent=0, sum=0;b=-1;for(i=500;i=800;i+)(for(j=2;ji-1)cnt+;a=b*i;sum+=a;b 二-b;)printf (%d %dn, ent, sum);return 0;22

16、.#includei nt ma i n ()(int i =2, A1=1, A2=1, A3, A4, n, M=10, j, S1=2,S2=0; for(n=1;n=3;n+)M=M*10;for(j=1;S1+A4M|S2=M;j+)|A3=A1+2*A2;A4=A2+2*A3;S1=S1+A3;S2=S1+A4;A1=A2;A2=A3;i+;)printf (%dn, i);)return 0;23.#incIude #include i nt ma i n ()(double x1, x2, x3=0, a; scanf (%lfr&a);x1=a;while (fabs (x1

17、-x3)=(x2=(x1+a/x1)/2;x3=x1;x1=x2;printf(.5lfn,x1); return 0;24.i nt ma i n () int i;doubIe a=1, sum=0;for(i=1;1/a=;i+)if(i%2=0)sum=sum-1/a;eIse sum=sum+1/a; a=a+2;)sum=sum*4;printf (%.6lfnH, sum);return 0;25.#include i nt ma i n () int a, i, n;for (a=6;a=1000;a+)n=0;for(i=1;ia;i+)if(a%i=0) n=n+i;)if

18、 (n=a) pr intf(%d=,a);for (i=1;ia;i+)i f (a% i =0)if (ia/2) printf i);e I se pr intf (%d, i);)printf(n);)return 0;三第三季已齐全21.#include #include i nt ma i n ()(1 nt x, y, a, b, I, s1, s2, t;scanf (%d%d%d%d%d,&x,&y,&a,&b,& l);if (xb)(t=s1/(a-b); pr intf (%dn, t); else if (ab)(t=s2/(a-b); pr intf (%dn, t

19、);)eIse if(ab)(t=s1/(b-a); pr intf (%dnn, t); eIse pr i ntf(imposs i bIenM);return 0;22.#include#include i nt ma i n ()(int N, i, j, k, x, a, cnt=O;scanf &N);for (k=7;k=0; i)a=(int)pow(10, i);x=j/a;if (x=7|k%7=0)(printf(M%d , k);break;)eIse j=j-a*x;)1return 0;)23.#include i nt ma i n ()(int a, b, c,

20、 d, e, f, g, h, i, j, n;scanf (%dM,&n);i f (n79)pr i ntf(er rornH);for (j=0;j=9;j+)for(i=0;i=9;i +)i f(i = j)continue;else for (h=0;h=9;h+) if (h=j |h=i)cont inue;eIse for(g=0;g=9;g+) if (g=h|g= i|g=j)continue;eIse for (f=0;f=9;f+) if (f=g|f=h|f= i |f=j)cont inue;eIse for(e=0;e=9;e+)if(e=f|e=g|e=h|e

21、=i|e=j)continue;eIse for (d=0;d=9;d+) if (d=e|d=f |d=g|d=h|d= i |d=j)cont inue; e I sefor (c=0;c=9;c+) if (c=d|c=e|c=f |c=g|c=h|c= i |c=j)cont inue; e I sefor (b=0;b=9;b+) if (b=c|b二二d|b=e|b=f |b=g|b=h|b二二i |b二j)cont inue; e I se for (a =0; a=9; a+) if (a=b | a=c | a 二二 d | a=e | a=f | a-g | ah | a=

22、 i | a=j) cont in ue;e I seif(doubIe(a*10000+b*1000+c*100+d*10+e)/doubIe(f*10000+g*1000+h*100+i*10+j)=n) pr i ntf (%d%d%d%d%d/%d%d%d%d%d=%dn, a, b, c, d, e, f, g, h, i, j, n);else continue;return 0;24O#include i nt ma i n ()int a=1,b1=0,b2,t, n;scanf(M%dw,&t);for(n=1;n=t;n+)b2=2*b1+3*a;a=b1;b1=b2;pr

23、intf (%d %dn, a, b2);return 0;#include#includei nt ma i n ()(long s=0,1=0, m=0;int n=0, i=0, j=0, k=0;scanf C%dn,&n);for(s=14000;s+)(for(i=1;i=99;i+=2)(l=s*100+i;for(m=3;m=(int)pow(I,;m+=2)(if(I%m=0)(goto B;1goto A;;)k+;if (n=k)printf (H%ld %ldn, s*100, I); break;)return 0;26.#include#include i nt m

24、a i n ()int m=0, n=0, g=0, s=0, i=0, k=0, j=0;scanf (%d%d&m,&n);for (i =(int)pow(10, n-1); i(int)pow(10, n); i +)j=i ;for(k=1;k=n;k+)if (j%10=m) if(i%m)g+; s+=i;);k=n;);j/=10;;1;printf (H%d %dn, g,s);return 0;27.#includei nt ma i n ()(int a二0, b二0, j=0;double i=0, s=0, k=0;scanf(%d%d”,&a,&b);for (i=

25、1;sa)j+;if(j=1)pr intf (%d ,(int) i);if (sb)printf(M%dnM,(int)(i-1););return 0;#includei nt ma i n ()(int k=0;scanf (%dH,&k);doubIe x=0, y=0;for (y=k+1;y=1/(doubIe) k;x+) i f (1/(doub I e) k=1/x+1/y) printf (H1/%d=1/%g+1/%gn,(int)k, x, y);1;);return 0;29.#include#include i nt ma i n ()(int n=0, i=0,

26、 j=0, k=0, a二0, b=0, c=0, g=0; scanf C%dn,&n);for (i=0; i(int)pow(2, n); i+) k=i ;for(j=1;j=n-2;j+)a=k%2;b=(k/2)%2;c=(k/4)%2;k/=2;if (a&b&c)g+; break;);printf(%dn,g);return 0;30.#includei nt ma i n ()(int n=0, i=0, k=1, d=1, m=0; scanf(M%dn,&n);int s20;for(i=1;i=n;i+) scanf (n%d&si-1);I;for (i=0;i n

27、-1;i+)k=i ;d=1;for (;km?d:m;if (m0)printf (%dn,m);e I seprintf(-1n); return 0;#includei nt ma i n ()(int i=0, j=0, k=0, a=0, b=0, c二0, I =0, m=0, n=0, d=0, p=0, q=0;for(i=1;i=3;i+)(for (j=1;j=9;j+)if (i!=j)(for(k=1;k=9;k+)(if (k!=j&i!=k)(a=i*100+j*10+k;b=a*2;c=a*3;l=b%10, d=c%10;m=(b%100)/10, p=(c%1

28、00)/10;n二b/100, q=c/100;if(I!=0&m!=0&n!=0&d!=0&p!=0&q!=0)if(i!= l&i!=m&i!=n& j!= I& j!=m&j!=n&k!= I&k!=m&k!=n) if (i!=d&i!=p& i!=q&j!二d&j!二p& j!=q&k!=d&k!=p&k!=q)if(I!=d&I!=p&I!=q&m!=d&m!=p&m!=q&n!=d& n!=p&n!=q)printf C%d %d %dnH, a, b, c);)1)return 0;#include #include i nt ma i n ()(int n, m, i ;do

29、ubIe b=0;scanf (%d %dn,&n,&m); for (i=n;i=m;i+)(b=b+1/pow(i,;)printf(n%.5lfn;b);return 0;33.# include i nt ma i n ()(int n, i, j, k, t;scanf (%dH,&n);k =0;for (i=1;i=n;i+) t=i ;wh i I e (t!=0)|j=t%10;t=t/10;if (j=1) k+;)printf(dn,k);return 0;# i ncIude i nt ma i n ()(int a, b, c. i;scanf (%d %d %d,&

30、a.&b.&c);for(i=10;i100)printf C-1nM);return 0;)35# i ncIude # i ncIude i nt ma i n ()(int a, b, c, i, A100;scanf (%d %d %dH,&a,&b,&c);A0=a/b;a=a%b;for (i=1;i =5)(Ac=Ac+1;for(i=c;i=0;i-)if (Ai=10) Ai-1+=1, Ai=O;)printf (%d. M, A0);for(i=1;i=c;i+)pr intf (%dM, Ai);pr i ntf(n);return 0;)四第四季齐全31.#inclu

31、deint getfloor (double a)(int b;if (aint (a)b= int (a)-1;eIse b=i nt (a);return printf(%dnrb);)i nt ma i n ()(doubIe a;scanf;getfIoor (a);return 0;#includei nt sum (i nt x)(int i=0, s=0;for(i=1;ix;i+)(if(x%i=0)s+=i;)return s;i nt ma i n ()(int a=0, b=0;scanf (%d%d,&a,&b);if (a=sum (b)&b=sum(a)(print

32、f (nYESn);)e I se(printf(N0n);1return 0;33.#includei nt move (i nt verge, i nt n)(int a=0;a=verge;if (n0)n=0-n;verge=n;a=(32-n);verge+=a;e I seIverge=n;a=(32-n);verge+=a;)return verge;i nt ma i n ()(uns i gned verge=0;int n=0;scanf (,%d%du,&verge,&n);pr i ntf(%dnM, move (verge,n);return 0;34.#includ

33、ei nt ma i n ()(int n=0, i=1;doub I e 80, b0, c0; scanf (%dH,&n);for(i=1;i=n;i+)(scanf(%lf,&c);a+=c*c;b+=c;c=n*b*b;printfC%.6lfn,c);return 0;#inc ludeOint C(int m, int n)(int i 二0, a二1,b=1;for (i=1; in)(pr i ntf (nwrongnH);e I se(printf (drT,C(m, n);1 return 0;)36.#inc ludeOi nt GZ (i nt n)(int i=0;

34、i=n/100;n%=100;i+=n/50;n=n%50;i+=n/10;n%=10;1 +=n/5;n%=5;i+=n/2;i+=n%2;return i;i nt ma i n ()(int n=0, i=1, x=0, k=0;scanf(%dM,&n);for(i=1;i=n;i+)(scanf (d,&x);k+二GZ(x);)printf(%dn,k); return 0;)37.#includei nt ma i n ()(int AH=0, AM=9, AS=0, BH=0, BM=0, BS=0;scanf (%d%d%d%d%d%dH,&AH,&AM,&AS,&BH,&B

35、M,&BS);if (AH=0&AM=0&AS=0&BH=0&BM=0&BS=0&AM60&AS60&BM60&BS59)|AM+=1;AS%=60;if (AM59)AH+=1;AM%=60;)printf (n%d %d %dnn,AH, AM, AS);)return 0;38.#includevoid DAO(unsigned long n)(if (n10)(printf(%dn,n); e I se (printf(,%d,n%10);n/=10;DAO (n);i nt ma i n ()(unsigned long n=0;scanf(%dM,&n);DAO (n);print

36、f (n);return 0;39.#include#includei nt JM(int n)int a=0, i=0;for(i=1;i999&n10000)(pr intf (%dn, JM(n);1return 0;40.#includeiniine int xchg(unsigned char n)(return (n%16)*16+n/16;i nt ma i n ()(uns i gned char n=0;scanf (%d,&n);pr intf (%dn, xchg(n);return 0;41#include #include int n;void fun(int A)(

37、1 nt i,s;for (i=0;in*2;i+=2)(s=Ai+Ai+1;pr i ntf(%dn, s%100);1i nt ma i n ()(int A81. j;scanf&n);for(j=0;jn*2;j+)scanf&Aj);fun (A);return 0;42#includei nt ack (int m, i nt n)(int x;if (m=0) x=n+1;eIse i f (n!=0) x=ack(m-1), ack(m, n-1) else x=ack(m-1,1);return x;)i nt ma i n ()int m, n;scanf&n);pr in

38、tf (%dn, ack(m. n);return 0;43#include#inc ludeOdoubIe integraI (double a. double b, doubIe(*f)(doubIe x)(int n=1000, i;doub I e h, x, s二;h=(b-a)/n;for(i=1;i=n;i+)s=s+(f(x)+f(x+h)*h/2;) return s;doubIe f (doubIe x)(return 1/(1+x*x);i nt ma i n ()(doub I e a, br t;scanf C%lf % If”,&a,&b);t=integra I (a, b, f);pr i ntf(%lfn,t);return 0;)44.# i nc ludeO# i ncIude int getbit (int n, int k)int i, I, mid, q, j=1, s=0; mid=n;for (i =1; i +)(l=mid%2;s=s+l

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁