-
Notifications
You must be signed in to change notification settings - Fork 9
/
ReadingNewspaper.cpp
39 lines (31 loc) · 1.6 KB
/
ReadingNewspaper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Reading Newspaper
You have a newspaper which has A lines to read. You decided to start reading the 1st line from Monday. You are given a schedule, B, where B[i] = number of lines you can read on that day. You are very strict in reading the newspaper and you will read as much as you can every day. Determine and return, which day of the week you will read the last line of the newspaper. Input Format:
The first argument contains the single integer A — the number of lines in the newspaper.
The second argument is an array B, of size 7 and those integers represent how many lines you can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly.
Note: It is guaranteed that at least one of the number in B[i] is larger than zero.
Output Format:
Return a single integer — the number of the day of the week, when you will finish reading the newspaper.
The days of the week are numbered starting with one in the order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
Constraints:
1 <= A <= 1000
1 <= B[i] <= 1000
Examples
Input 1:
A = 100
B = [15, 20, 20, 15, 10, 30, 45]
Output 1:
6
Explanation 1:
By the end of Monday and therefore, by the beginning of Tuesday, you will have 85 lines left. You have 65 lines left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday, you will finish reading the newspaper.
*/
int Solution::solve(int A, vector<int> &B) {
while(A>0){
for(int i=0;i<B.size();i++){
if(B[i]>=A){
return i+1;
}else{
A-=B[i];
}
}
}
}