Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C++ code to count days to complete reading book
Suppose we have an array A with n elements and have another value t. On ith day Amal spends A[i] seconds in work. In the free time he reads a book. The entire book will take t seconds to complete. We have to find how many days he will need to read the complete book.
So, if the input is like A = [86400, 86398]; t = 2, then the output will be 2, because one day has 86400 seconds, and first day is totally blocked. On second day he will get 2 seconds to complete the book.
Steps
To solve this, we will follow these steps −
cnt := 1 n := size of A for initialize i := 0, when iExample
Let us see the following implementation to get better understanding −
#includeusing namespace std; int solve(vector A, int t){ int cnt = 1; int n = A.size(); for (int i = 0; i A = { 86400, 86398 }; int t = 2; cout Input
{ 86400, 86398 }, 2Output
2
Advertisements
