40分求救!!!(必关)
查看原帖
40分求救!!!(必关)
1363161
haoyiran2013楼主2024/10/31 20:02
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, x, z = 0;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cin >> x;
	int n2 = n;
	int i = 0;
	while (n2 != 0) {
		if (x > a[i]) {
			z++;
			x -= a[i];
		}
		i++;
		n2--;
	}
	cout << z;
	return 0;
}
2024/10/31 20:02
加载中...