30分,求教
查看原帖
30分,求教
894727
qingchrush楼主2024/6/2 19:53
#include <iostream>
#include <queue>
using namespace std;

queue<int> q;

int main()
{
    int m, n, cnt = 0;
    cin >> m >> n;
    for (int i = 1; i <= n; ++i)
    {
        int a, flag = 0;
        cin >> a;
        for (int j = 1; j <= q.size(); ++j)
        {
            if (q.front() == a)
            {
                flag = 1;
                break;
            }
            else
            {
                int temp = q.front();
                q.pop();
                q.push(temp);
            }
        }
        if (flag == 0)
        {
            q.push(a);
            ++cnt;
        }
        if (m < q.size())
        {
            q.pop();
        }
    }
    cout << cnt << endl;
    system("pause");
    return 0;
}
2024/6/2 19:53
加载中...