关于stl越界
查看原帖
关于stl越界
813901
tuiqian666楼主2024/10/27 11:56

考场没想到empty的时候 q.front()直接gg 这代码是不是直接0了

#include<bits/stdc++.h>
using namespace std;
queue<int> q;
int a[100010];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	for(int i = 1;i <= n;i++)
	{
		if(a[i] > q.front())
		{
			q.pop();
		}
		q.push(a[i]);
	}
	cout << q.size() << '\n';
	return 0;
}

2024/10/27 11:56
加载中...