CF139A Petr and Book 题解
Content
小 P 有一本 \(n\) 页的书,现给出他一周七天每天的阅读页数,求它在星期几读完这本书。
数据范围:\(1\leqslant n\leqslant 1000\)。
Solution
由于数据范围很小,所以我们尝试直接模拟,每一天读完减去当天读的页数,直到剩余页数小于等于 \(0\) 为止,此时的星期数就是我们要求的了。
Code
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int n, a[17], cur = 1;
int main() {
scanf("%d", &n);
for(int i = 1; i <= 7; ++i)
scanf("%d", &a[i]);
while(1) {
n -= a[cur];
if(n <= 0) break;
cur++;
if(cur > 7) cur = 1;
}
printf("%d", cur);
}

浙公网安备 33010602011771号