出不来

P1478 陶陶摘苹果(升级版)

安全修改 @ 2019-03-10 19:41:59

#include<bits/stdc++.h>
using namespace std;
int main()
{
int sum=0,c,d,e,f;
scanf("%d%d%d%d",&c,&d,&e,&f);
int a[10],b[10];
for(int i=1;i<=c;i++)
scanf("%d%d",&a[i],&b[i]);
sort(b,b+c-1);
while(d>0){
int i=1;
if(a[i]<=e+f){
if(f>b[i]){
f-=b[i];
i++;
sum++;
continue;
    }
    else 
    break;      
}

}
printf("%d",sum);
return 0;
}

by Jelly_Goat @ 2019-03-10 19:47:04

码风有待提高啊


by dead_gun @ 2019-03-10 19:48:16

while循环没有终止条件吧,死循环


by 安全修改 @ 2019-03-10 20:01:34

break直接跳出循环


by dead_gun @ 2019-03-10 20:06:59

你sort把b和a的关系破坏了吧


|