4314: GESP C++三级样题_3逛商场
内存限制:128 MB
时间限制:1.000 S
评测方式:文本比较
命题人:
提交:13
解决:9
题目描述
样例输入 复制
6
7 5 9 10 7 4
30
样例输出 复制
4
提示
#include <bits/stdc++.h> using namespace std; int price[100]; int main() { int n = 0, x = 0, cnt = 0; cin >> n; for (int i = 0; i < n; i++) cin >> price[i]; cin >> x; for (int i = 0; i < n; i++) { if (x >= price[i]) { //买得起就买 x-= price[i]; cnt++; } } cout << cnt; return 0; }