这是比较水的一道题
判断出周一到周五以及周末的条件即可,但要切记最后要的是天数(i),而不是总量res。
i--的目的是得到i之后是第二天的i而不是我们需要的结束的i,所以需要i--一次。
#include<iostream>
using namespace std;
class Solution {
public:
int shuati(int a, int b, int n) {
long long int res = 0, i;
for (i = 1; res <= n; ++i) {
if (i % 7 <= 5 && i % 7 >= 1) res += a;
else res += b;
}
i--;
return i;
}
};
int main() {
Solution s;
int a, b, n;
cin >> a >> b >> n;
int i = s.shuati(a, b, n);
cout << i << endl;
return 0;
}