西工大C语言学习知识POJ习题集规范标准答案.doc
-*一.1.第一季10题全(注:第五题问题已经解决,确认AC!)#includeintmain()inta,b,sum;scanf(%d%d,&a,&b);sum=a+b;printf(%dn,sum);return0;2.#include#definePI3.1415926intmain()doubler,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(%.2lfn%.2lfn%.2lfn%.2lfn%.2lfn,l,s,sq,vq,vz);return0; 3.#includeintmain()inta,b,c;doubled,e;scanf(%d%d%d,&a,&b,&c);d=a+b+c;e=d/3;printf(%lfn%lfn,d,e);return0;4.#includeintmain()inta,b,c;scanf(%d%d%d,&a,&b,&c);if(ab)a=b;if(ac)a=c;printf(%dn,a);return0; 5.#includeintmain()inti=0,j=0,k=1;chara6;while(ai=getchar()!=n)i+;for(;i0;i-)if(aj=ai-1)j+;continue;elsek=0;break;if(k=1)printf(yesn);elseprintf(non);6.#includeintmain()doublea,c;scanf(%lf,&a);switch(int)a/10)case0:c=a*0.1;break;case1:c=(a-10)*0.075+10*0.1;break;case2:case3:c=(a-20)*0.05+10*0.075+10*0.1;break;case4:case5:c=(a-40)*0.03+20*0.05+10*0.075+10*0.1;break;case6:case7:case8:case9: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(%lfn,c);return0;7.#includeintmain()doublea,b,c;scanf(%lf,&a);c=(int)a;if(ac)a=c+1;if(a15)b=(a-15)*2.1+7+13*1.5;elseif(a2)b=(a-2)*1.5+7;elseb=7;printf(%lfn,b);return0;8.#includeintmain()inta,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)case1:n=c;break;case2:n=g+c;break;case3:n=g+e+c;break;case4:n=g+e+g+c;break;case5:n=g+e+g+f+c;break;case6:n=g+e+g+f+g+c;break;case7:n=g+e+g+f+g+f+c;break;case8:n=g+e+g+f+g+f+g+c;break;case9:n=g+e+g+f+g+f+g+g+c;break;case10:n=g+e+g+f+g+f+g+g+f+c;break;case11: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(%dn,n);return0;9.#includeintmain()intx;scanf(%d,&x);if(x=90&x=80)printf(Bn);elseif(x=70)printf(Cn);elseif(x=60)printf(Dn);elseprintf(En);return0;10.#includeintmain()doublex,y,s;scanf(%lf,%lf,&x,&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);return1;printf(10n);return0;二。第二季15题全11. #includeint main() int x=0,a=0,c=0,i=1;scanf(%d%d,&x,&a);c=x; for(i=1;ia;i+)c=(c*x)%1000;if(c100)if(c=100)printf(%dn,c);return 0;12. #includeint main() 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(a%4!=0) k=0; ; ;a=a/4*5+1;if(k=1)printf(%d %dn,a,b); break;return 0;13。#include#includeint main()int i=1,n=0,b=0;double j=0,k=0,m=0;scanf(%d,&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);printf(%.6lfn,j);return 0;14. #include#includeint main() 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; if(m=1)printf(%d ,a);printf(n);return 0;15.#include#includeint main() int a=0,b=0,c=0;scanf(%d,&a); b=(int)pow(a,2);c=(int)pow(a,3);if(a%2) printf(%d*%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(n);if(a%2=0) int n=1; printf(%d*%d*%d=%d=%d,a,a,a,c,b+1-a); for(;na;n+) printf(+%d,b+1-a+n*2); printf(n);return 0;16#include#includeint main() int a=0,b=0,c=0,d=0,e=0,x=0,y=0,z=0,u=0,v=0; double f=0;for(a=0;a=2;a+)double 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+0.0084*12*8,a)*pow(1+0.0075*12*5,b)*pow(1+0.0069*12*3,c)*pow(1+0.0066*12*2,d)*pow(1+0.0063*12,e);if(fm)f=m; x=a,y=b,z=c,u=d,v=e;printf(%d %d %d %d %dn%.2lfn,x,y,z,u,v,f);return 0;17.#include#includeint main() double a=0;int i=0,b=0;scanf(%lf,&a); b=(int)a;for(;(int)(b/pow(10,i);)i+; printf(%dn,i);return 0;18。#includeint main() double a=1,b=2,i=1,m=0;for(;i=20;i+) m+=b/a;b=a+b;a=b-a;printf(%.6lfn,m);return 0;19.#include#includeint main() double a=0,b=0,c=0,e=0;scanf(%lf%lf,&a,&b); for(;b-a0.0001;) c=2*pow(a,3)-4*pow(a,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; else a=(a+b)/2; ; ;printf(%.2lfn,a);return 0;20.#includeintmain()chari,j,k;for(i=X;i=Z;i+)for(j=X;j=Z;j+)if(i!=j)for(k=X;k=Z;k+)if(i!=k&j!=k)if(k!=X)&(k!=Z)&(i!=X)printf(A=%cnB=%cnC=%cn,i,j,k);return0; 21.#includeint main()int a,b,i,j,cnt=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,cnt,sum);return 0;22.#includeint main()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.#include #include int main() double x1,x2,x3=0,a; scanf(%lf,&a); x1=a; while(fabs(x1-x3)=0.00001) x2=(x1+a/x1)/2; x3=x1; x1=x2; printf(%.5lfn,x1); return 0;24.#include int main() int i;double a=1,sum=0;for(i=1;1/a=0.000001;i+) if(i%2=0)sum=sum-1/a; else sum=sum+1/a; a=a+2;sum=sum*4;printf(%.6lfn,sum);return 0;25. #include int main() 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(n=a) printf(%d=,a);for (i=1;ia;i+)if(a%i=0)if(ia/2) printf(%d+,i);else printf(%d,i);printf(n);return 0;三.第三季已齐全21.#include #include int main()int x,y,a,b,l,s1,s2,t;scanf(%d%d%d%d%d,&x,&y,&a,&b,&l);if(xb)t=s1/(a-b);printf(%dn,t);else if(ab)t=s2/(a-b);printf(%dn,t);else if(ab)t=s1/(b-a);printf(%dn,t); else printf(impossiblen); return 0;22.#include#includeintmain()intN,i,j,k,x,a,cnt=0;scanf(%d,&N);for(k=7;k=0;i-)a=(int)pow(10,i);x=j/a;if(x=7|k%7=0)printf(%d,k);break;elsej=j-a*x;return0;23.#includeint main()int a,b,c,d,e,f,g,h,i,j,n;scanf(%d,&n);if(n79)printf(errorn);for(j=0;j=9;j+)for(i=0;i=9;i+)if(i=j)continue;else for(h=0;h=9;h+)if(h=j|h=i)continue;else for(g=0;g=9;g+)if(g=h|g=i|g=j)continue;else for(f=0;f=9;f+)if(f=g|f=h|f=i|f=j)continue;else for(e=0;e=9;e+)if(e=f|e=g|e=h|e=i|e=j)continue;else for(d=0;d=9;d+)if(d=e|d=f|d=g|d=h|d=i|d=j)continue;else for(c=0;c=9;c+)if(c=d|c=e|c=f|c=g|c=h|c=i|c=j)continue;else for(b=0;b=9;b+)if(b=c|b=d|b=e|b=f|b=g|b=h|b=i|b=j)continue;else for(a=0;a=9;a+)if(a=b|a=c|a=d|a=e|a=f|a=g|a=h|a=i|a=j)continue;else if(double(a*10000+b*1000+c*100+d*10+e)/double(f*10000+g*1000+h*100+i*10+j)=n)printf(%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;24。#includeint main()int a=1,b1=0,b2,t,n; scanf(%d,&t); for(n=1;n=t;n+) b2=2*b1+3*a; a=b1; b1=b2; printf(%d %dn,a,b2); return 0;25.#include#includeintmain()longs=0,l=0,m=0;intn=0,i=0,j=0,k=0;scanf(%d,&n);for(s=14000;s+)for(i=1;i=99;i+=2)l=s*100+i;for(m=3;m=(int)pow(l,0.5);m+=2)if(l%m=0)gotoB;gotoA;B:;k+;if(n=k)printf(%ld%ldn,s*100,l);break;A:;return0;26.#include#includeint main() 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; ;printf(%d %dn,g,s);return 0;27.#includeintmain()inta=0,b=0,j=0;doublei=0,s=0,k=0;scanf(%d%d,&a,&b);for(i=1;sa)j+;if(j=1)printf(%d,(int)i);if(sb)printf(%dn,(int)(i-1);return0;28.#includeint main() int k=0;scanf(%d,&k);double x=0,y=0; for(y=k+1;y=1/(double)k;x+)if(1/(double)k=1/x+1/y)printf(1/%d=1/%g+1/%gn,(int)k,x,y);return 0;29.#include#includeint main() int n=0,i=0,j=0,k=0,a=0,b=0,c=0,g=0;scanf(%d,&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. #includeint main()int n=0,i=0,k=1,d=1,m=0;scanf(%d,&n); int s20;for(i=1;i=n;i+)scanf(%d,&si-1);for(i=0;in-1;i+)k=i;d=1;for(;km?d:m;if(m0)printf(%dn,m);elseprintf(-1n);return 0;31#includeintmain()inti=0,j=0,k=0,a=0,b=0,c=0,l=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%100)/10;n=b/100,q=c/100;if(l!=0&m!=0&n!=0&d!=0&p!=0&q!=0)if(i!=l&i!=m&i!=n&j!=l&j!=m&j!=n&k!=l&k!=m&k!=n)if(i!=d&i!=p&i!=q&j!=d&j!=p&j!=q&k!=d&k!=p&k!=q)if(l!=d&l!=p&l!=q&m!=d&m!=p&m!=q&n!=d&n!=p&n!=q)printf(%d%d%dn,a,b,c);return0;32.#include #include int main()int n,m,i;double b=0;scanf(%d %d,&n,&m);for (i=n;i=m;i+)b=b+1/pow(i,2.0);printf(%.5lfn,b);return 0;33.#include int main()int n,i,j,k,t;scanf(%d,&n);k=0;for(i=1;i=n;i+)t=i;while(t!=0)j=t%10;t=t/10;if(j=1)k+;printf(%dn,k);return 0;34.#includeintmain()inta,b,c,i;scanf(%d%d%d,&a,&b,&c);for(i=10;i100)printf(-1n);return0;35#include #include int main()int a,b,c,i,A100;scanf(%d %d %d,&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=0; printf(%d.,A0);for(i=1;i=c;i+)printf(%d,Ai);printf(n);return 0;四。第四季齐全31.#includeint getfloor(double a)int b;if(aint(a)b=int(a)-1;else b=int(a);return printf(%dn,b);int main()double a;scanf(%lf,&a);getfloor(a);return 0;32.#includeint sum(int x) int i=0,s=0;for(i=1;ix;i+) if(x%i=0) s+=i;return s;int main() int a=0,b=0;scanf(%d%d,&a,&b); if(a=sum(b)&b=sum(a) printf(YESn);elseprintf(NOn);return 0;33.#includeint move(int verge,int n) int a=0;a=verge; if(n0) n=0-n; verge=(32-n);
收藏