1 solutions
-
0
#include #include #include
int main() { // 图书单价表,使用数组存储每种图书的单价 const std::array<double, 10> prices = {28.9, 32.7, 45.6, 78.0, 35.0, 86.2, 27.8, 43.0, 56.0, 65.0};
// 定义一个数组来存储每种图书的购买数量 int quantities[10]; // 读取每种图书的购买数量 for (int i = 0; i < 10; ++i) { std::cin >> quantities[i]; } // 计算总费用 double totalCost = 0.0; for (int i = 0; i < 10; ++i) { totalCost += quantities[i] * prices[i]; } // 输出总费用,精确到小数点后一位 std::cout << std::fixed << std::setprecision(1) << totalCost << std::endl; return 0;
}
- 1
Information
- ID
- 6903
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 1
- Tags
- # Submissions
- 10
- Accepted
- 5
- Uploaded By