A. Petr and book

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactlyNPages.

Petr decided to start reading it starting from the next day, that is, from Monday. petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. some days are so busy that Petr will have no time
Read whatsoever. However, we know that he will be able to read at least one page a week.

Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.

Input

The first input line contains the single integerN(1 digit ≤ DigitNLimit ≤00001000)
-The number of pages in the book.

The second line contains seven non-negative space-separated integers that do not exceed 1000-those integers represent how many pages Petr can read
On Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. it is guaranteed that at least one of those numbers is larger than zero.

Output

Print a single number-the number of the day of the week, when Petr will finish reading the book. the days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.

Sample test (s) Input
10015 20 20 15 10 30 45
Output
6
Input
21 0 0 0 0 0 0
Output
1
Note

Note to the first sample:

By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. he has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages
Something else ).

Note to the second sample:

On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.

Solution Description: cyclically judge the problem

#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;int main(){int n,i;int a[7];scanf("%d",&n);for(i=0;i<7;i++){scanf("%d",&a[i]);}while(1){if(i==7){i=0;}n-=a[i];if(n<=0){printf("%d\n",i+1);break;}i++;}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.