// accessing mapped values #include <iostream> #include <algorithm> #include <map> #include <string> #include <queue> using namespace std; int main () { map<int,int> m; queue<int> q; int T,N,n; cin >> T; while(T--){ cin >> N; n=N; while(n--){ int k; cin >> k; if (m[k]) m[k]++; else { m[k]=1; q.push(k); } } bool found=false; while(!q.empty() && !found){ int k = q.front(); if (m[k]>N/2){ cout << k << endl; found = true; } q.pop(); } if (!found) cout << -1 << endl; } return 0; }
沒有留言:
張貼留言