Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
int main(){
const int numDays = 7;
int numPages; scanf("%d\n", &numPages);
int weekPages[numDays] = {0}; int total = 0;
for(int k = 0; k < numDays; k++){scanf("%d", weekPages + k); total += weekPages[k];}
numPages %= total;
if(numPages == 0){numPages = total;}
for(int k = 0; k <= numDays; k++){
if(numPages <= 0){printf("%d\n",k); break;}
numPages -= weekPages[k];
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
100
15 20 20 15 10 30 45
15 20 20 15 10 30 45
Output
6
Demonstration
Codeforces Solution-A. Petr and Book-Solution in C, C++, Java, Python