该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
int g[10];
void find_two_smallest(int n, int *smallest, int *second_smallest, int j, int k);
int main(void){
int n, i, a=0, b=0, sum=0, total=0;
int *smallest=g;
int *second_smallest=g;
printf("输入果子堆数:");
scanf("%d",&n);
printf("输入每堆果子的重量:");
for(i=0;i
scanf("%d",&g[i]);
}
for(i=1;i<=n-1;i++){
find_two_smallest(n, smallest, second_smallest, a, b);
sum=*smallest+*second_smallest;
g[a]=sum;
g[b]=0;
total+=sum;
smallest=g;
second_smallest=g;
a=b=0;
}
printf("总共花费的体力:%d",total);
return 0;
}
void find_two_smallest(int n, int *smallest, int *second_smallest, int j, int k){
int i;
if(g[0]
*smallest=g[0];
j=0;
*second_smallest=g[1];
k=1;
}
else{
*smallest=g[1];
j=1;
*second_smallest=g[1];
k=0;
}
for(i=2;i
if(g[i]
*second_smallest=*smallest;
k=j;
*smallest=g[i];
j=i;
}
else if(g[i]
*second_smallest=g[i];
k=i;
}
}
}
这是我自己写的程序,我觉得挺简单易懂的,就是搞不懂到底在哪里逻辑出错了,一直得不到正确的答案