0分求助(来自一个只会优先队列排序的蒟蒻)
查看原帖
0分求助(来自一个只会优先队列排序的蒟蒻)
1044048
Algorithm_ZRF楼主2023/8/4 18:14
#include <bits/stdc++.h>
using namespace std;
int n, m, a[105];
priority_queue<int, vector<int>, greater<int>> q;
inline void input() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int b = a[1];
	for (int i = 1; i <= n; ++i) {
		if (i != 1)
			if (a[i] == b) {
				b = a[i];
				continue;
			}
		q.push(a[i]);
		m++;
	}
}

inline void output() {
	cout << m << endl;
	while (!q.empty()) {
		cout << q.top() << ' ';
		q.pop();
	}
}

int main() {
	input();
	output();
	return 0;
}
2023/8/4 18:14
加载中...