lundi 26 mars 2018

Idleness limit exceeded error! What am I doing wrong?

I'm solving a problem but keep getting Idleness limit exceeded error. What am I doing wrong?
The problem is you first get number of pages in a book and then number of pages read in everyday in a week as inputs. The output is the number day in the week the book is finished.

Sample input

100

15 20 20 15 10 30 45

Sample output

6

Sample input

2

1 0 0 0 0 0 0

Sample output

1

#import <iostream>

using namespace std;
int main() {
int A,sum;
cin>>A;
sum=0;
int B[7];
for(int i=0;i<7;i++){
    cin>>B[i];
}
for(int i=0;;i++){
    sum=sum+B[i];
    if(sum>=A){
        cout<<i+1<<endl;
        break;
    }
    if(i==6){
        i=-1;
    }
}
return 0;
}

Aucun commentaire:

Enregistrer un commentaire