提交记录 #224
提交时间:2024-11-16 10:41:42
语言:c
状态:Unaccepted
编译情况:编译成功
固定测试点#1:
额外测试点#1:
M32【期中测验3】商场抽奖
#include <stdio.h>
int main() {
// 定义奖品价格数组
int prices[5];
int totalValue, totalItems;
// 输入 5 种奖品的价格
for (int i = 0; i < 5; i++) {
scanf("%d", &prices[i]);
}
// 输入奖品总值和总件数
scanf("%d %d", &totalValue, &totalItems);
// 枚举所有可能的奖品数量组合
for (int a = 0; a <= totalItems; a++) {
for (int b = 0; b <= totalItems; b++) {
for (int c = 0; c <= totalItems; c++) {
for (int d = 0; d <= totalItems; d++) {
for (int e = 0; e <= totalItems; e++) {
// 检查当前组合的总件数和总价值
if ((a + b + c + d + e == totalItems) &&
(a * prices[0] + b * prices[1] + c * prices[2] +d * prices[3] + e * prices[4] == totalValue)) {
// 输出符合条件的组合
printf("%d,%d,%d,%d,%d\n", a, b, c, d, e);
return 0; // 找到第一个符合条件的组合后退出程序
}
}
}
}
}
}
// 如果没有找到符合条件的组合
printf("No solution found\n");
return 0;
}