提交记录 #76
提交时间:2024-10-29 22:49:19
语言:c
状态:CompileError
编译情况:编译错误
code.c: In function ‘find_prizes’:
code.c:26:5: warning: ‘main’ is normally a non-static function [-Wmain]
26 | int main() {
| ^~~~
code.c:42:1: error: expected declaration or statement at end of input
42 | }
| ^
At top level:
code.c:26:5: warning: ‘main’ defined but not used [-Wunused-function]
26 | int main() {
| ^~~~
固定测试点暂不可用
附加测试点暂不可用
M32【期中测验3】商场抽奖
#include <stdio.h>
void find_prizes(int prices[5], int total_value, int total_count) {
// 枚举每种奖品的数量
for (int a = 0; a <= total_count; a++) {
for (int b = 0; b <= total_count - a; b++) {
for (int c = 0; c <= total_count - a - b; c++) {
for (int d = 0; d <= total_count - a - b - c; d++) {
int e = total_count - a - b - c - d; // 计算第五种奖品的数量
// 计算总价值
int current_value = a * prices[0] + b * prices[1] + c * prices[2] + d * prices[3] + e * prices[4];
// 检查总价值和总件数是否匹配
if (current_value == total_value && (a + b + c + d + e) == total_count) {
// 找到第一组符合条件的组合,输出并返回
printf("%d,%d,%d,%d,%d\n", a, b, c, d, e);
return; // 退出函数,停止寻找
}
}
}
}
}
int main() {
int prices[5];
int total_value, total_count;
// 输入奖品价格
for (int i = 0; i < 5; i++) {
scanf("%d", &prices[i]);
}
// 输入总价值和总件数
scanf("%d %d", &total_value, &total_count);
// 查找符合条件的奖品组合
find_prizes(prices, total_value, total_count);
return 0;
}