int main()
{
int szNum[25];
int index = 0;
int tmp = 0;
int sub = 0;
bool finish = false;
printf("Enter job sizes now:");
while (index < 25)
{
scanf("%d", &tmp);
if (tmp == -1)
{
finish = true;
break;
}
szNum[index++] = tmp;
}
if (finish == true || index == 25)
{
while (1)
{
printf("Enter time limit of the computer:");
scanf("%d", &sub);
if (sub < 0)
{
printf("Error! Non-negative values only!\n");
}
else
{
break;
}
}
}
bool capacity_order = false;
int capacity = 0;
for (int i = 0;; i ++)
{
if (i == index && capacity_order == false)
{
i = 0;
}
if (sub >= szNum[i])
{
//printf(" %d ", sub - szNum[i]);
sub = sub - szNum[i];
capacity ++;
}
else if(!capacity_order)
{
printf("Job capacity in current order: %d \n", capacity);
capacity_order = true;
}
if (i == index && capacity_order == true)
{
break;
}
}
printf("Optimized job capacity: %d \n", capacity);
return 0;
}
温馨提示:答案为网友推荐,仅供参考