提交记录 #225
提交时间:2024-11-16 10:43:00
语言:c
状态:CompileError
编译情况:编译错误
code.c:38:5: error: redefinition of ‘main’
38 | int main() {
| ^~~~
code.c:4:5: note: previous definition of ‘main’ was here
4 | int main() {
| ^~~~
固定测试点暂不可用
附加测试点暂不可用
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; // 找到第一个符合条件的组合后退出程序
}
}
}
}
}
}
return 0;
}
#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; // 找到第一个符合条件的组合后退出程序
}
}
}
}
}
}
return 0;
}