[牛客]小红的数组分配

题目

思路

  • 去考虑sort排序为相同数字为偶数个,输出格式
  • 错误的去思考了数组为pair

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
int i,j,k,n,m,t,res,a[N]={0};
string s;
void slove(){
	cin >> n;
	for(i=0;i<n*2;i++) cin >> a[i];
	sort(a,a+2*n);
	for(i=0;i<2*n;i+=2){
		if(a[i]!=a[i+1]) {
			cout << "-1";
			return; 
		} 
	}
	for(j=0;j<2;j++){
		for(i=0;i<2*n;i+=2){
			cout << a[i] << " "; 
		}
		cout << "\n";
	}

}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	slove();
}
posted @ 2024-03-14 16:14  zzzz-z  阅读(39)  评论(0编辑  收藏  举报