为什么输出总是0呀
查看原帖
为什么输出总是0呀
957640
Michelle01楼主2023/8/25 16:58
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;

int a[1010];
int main() {

	queue<int> q;
	int ans = 0;
	int m, n;
	cin >> m >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i]) {
			continue;
		}
		else {
			if (q.size() < m) {
				q.push(a[i]);
				ans++;
				a[i] = true;
			}
			else if (q.size() >= m) {
				a[i] = false;
				q.pop();
			}
		}
	}
	cout << ans << endl;

	return 0;
}

2023/8/25 16:58
加载中...