7-1 自动打包机
c1保存当前箱子内的瓜数 c2是已装箱的箱子数量 c3为已装满的箱子内的瓜数
如果当前箱子到结束都没有装满c1是不会累加到c3内的 因为没有装满 只有每次装满c1才会加到c3里
#include<bits/stdc++.h>
using namespace std;
int main(void) {
//now 现在的重量 c1装箱子里的瓜数 c2已装箱数
int n, w, t, now = 0, c1 = 0, c2 = 0, c3 = 0;
cin >> n >> w;
for (int i = 0; i < n; ++i) {
cin >> t;
if (now + t < w) {
//留着
now += t;
c3++;
// cout << "装入:" << t << endl;
} else if (now + t == w) {
//打包
c1 += (c3 + 1);
now = 0;
c2++;
c3 = 0;
// cout << "装入:" << t << endl;
} else continue;
}
cout << c2 << " " << c1;
return 0;
}
7-2 用药统计
我直接每次输入两个getchar()抽去MD 保存后5位的数字
<