计算过道和栏杆的造价.c 822 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define PI 3.14159
  4. #define FENCE_COST_PER_METER 55
  5. #define PATH_COST_PER_SQUARE_METER 40
  6. #define PATH_WIDTH 3
  7. int main() {
  8. double pool_radius;
  9. double total_radius, fence_cost, path_cost;
  10. double pool_area, total_area, path_area;
  11. scanf("%lf", &pool_radius);
  12. // 计算总半径(游泳池半径 + 过道宽度)
  13. total_radius = pool_radius + PATH_WIDTH;
  14. // 计算栅栏造价
  15. fence_cost = 2 * PI * total_radius * FENCE_COST_PER_METER;
  16. // 计算过道面积和造价
  17. pool_area = PI * pool_radius * pool_radius;
  18. total_area = PI * total_radius * total_radius;
  19. path_area = total_area - pool_area;
  20. path_cost = path_area * PATH_COST_PER_SQUARE_METER;
  21. // 输出结果,保留整数
  22. printf("%d %d\n", (int)round(path_cost), (int)round(fence_cost));
  23. return 0;
  24. }