24分求掉
查看原帖
24分求掉
1047537
wuzhuoran楼主2024/8/7 17:08
#include<bits/stdc++.h>
using namespace std;

int n,t,a[200005];

int main(){
	cin>>t;
	while(t--){
		map<int,int> mp;
		cin>>n;
		for(int i=1; i<=n; i++){
			cin>>a[i];
		}
		int cnt=0;
		for(int i=1; i<=n; i++){
			if(	i!=n&&a[i]==a[i+1]&&mp[a[i]]==0){
				mp[a[i]]=1;
				cnt++;
				if(cnt==1){
					cout<<a[i];
				}
				else{
					cout<<' '<<a[i];
				}
			}
			else if(i!=n-1&&a[i]==a[i+2]&&mp[a[i]]==0){
				mp[a[i]]=1;
				cnt++;
				if(cnt==1){
					cout<<a[i];
				}
				else{
					cout<<' '<<a[i];
				}
			}			
		}
		if(cnt==0){
			cout<<-1;
		}
		cout<<endl;
	}
	return 0;
}
2024/8/7 17:08
加载中...