资源描述:
《算法竞赛入门经典各章习题答案.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第一章习题1-1#includeintmain(){inta,b,c;doubled;scanf("%d%d%d",&a,&b,&c);d=(double)(a+b+c);printf("%.3lf",d/3.0);return0;}习题1-2#includeintmain(){intf;doublec;scanf("%d",&f);c=5*(f-32)/9;printf("%.3lf",c);return0;}习题1-3#includeintmain(){intn;scanf("%d"
2、,&n);printf("%d",(n*(1+n))/2);return0;}习题1-4#include#include#definepi4.0*atan(1.0)intmain(){intn;scanf("%d",&n);printf("%lf",sin((pi*n)/180));printf("%lf",cos((pi*n)/180));return0;}习题1-5#includeintmain(){doublex1,y1,x2,y2,a;scanf("%lf%lf%lf%lf",
3、&x1,&y1,&x2,&y2);a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));printf("%lf",a);return0;}习题1-6#includeintmain(){intn;scanf("%d",&n);if(n%2==0){printf("YES");}else{printf("NO");}return0;}习题1-7#includeintmain(){intn;doublea;scanf("%d",&n);a=n*95.0;if(a<300){prin
4、tf("%.2lf",a);}else{printf("%.2lf",a*0.85);}return0;}习题1-8#include#includeintmain(){doublen;scanf("%lf",&n);printf("%.2lf",fabs(n));return0;}习题1-9#includeintmain(){inta,b,c;scanf("%d%d%d",&a,&b,&c);if(a==b&&b==c){printf("no");}if((a*a+b*b==c*c)
5、
6、
7、(a*a+c*c==b*b)
8、
9、(b*b+c*c==a*a)){printf("yes");}else{printf("no");}return0;}习题1-10#includeintmain(){intn;scanf("%d",&n);if(n%4==0){if(n%100!=0){printf("no");}else{if(n%400==0){printf("yes");}else{printf("no");}}}else{printf("no");}return0;}第二章习题2-1#include
10、intmain(){intn,count=0;scanf("%d",&n);while(n>0){count++;n=n/10;}printf("%d",count);return0;}习题2-2#includeintmain(){inta,b,c;for(inti=100;i<=999;i++){a=i%10;b=i/10%10;c=i/100;if(i==a*a*a+b*b*b+c*c*c){printf("%d",i);}}return0;}习题2-3#includeintmain
11、(){inti,a,b,c;scanf("%d%d%d",&a,&b,&c);for(i=10;i<=100;i++){if(i%3==a&&i%5==b&&i%7==c){printf("%d",i);}}if(i==101){printf("noanswer");}return0;}习题2-4#includeintmain(){inti,j,k,n;scanf("%d",&n);for(i=n;i>0;i--){for(k=0;k12、intf("#");}printf("");}return0;}习题2-5文件题,南邮竞赛基本不涉及。。。习题2-6#