代碼如下
#include
int main()
{
void paixu(float food[100][2], int N);
float M,total = 0;
int N,j,i;
while (scanf("%f%d", &M, &N)&&M != -1 && N != -1)
{
float food[100][2] = { 0 };
for (i = 0; i < N; i++)
{
for (j = 0; j < 2; j++)
scanf("%f", &food[i][j]);
}
paixu(food, N);
for (i = 0; M>food[i][1]; i++)
{
M = M - food[i][1];
total += food[i][0];
}
total = total + M / food[i][1] * food[i][0];
printf("%.3f\n", total);
}
return 0;
}
void paixu(float food[100][2],int N)
{
int i, j, k;
float t_1, t_2;
for (i = 0; i < N; i++)
{
k = i;
for (j = i + 1; j < N; j++)
{
if (food[k][1] < food[j][1])
k = j;
}
if (i != k)
{
t_1 = food[i][1];
t_2 = food[i][0];
food[i][1] = food[j][1];
food[i][0] = food[j][0];
food[j][1] = t_1;
food[j][0] = t_2;
}
}
}求高手幫忙找下哪裡錯了
數組的下標就是從0開始的啊