Problem: NUMBERS (It seemed rather easy at first!)
My solution:
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
bool comp(pair<string, lld> p1, pair<string, lld> p2) {
return p1.second < p2.second;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
lld T;
cin >> T;
while (T--) {
lld N;
cin >> N;
vector<pair<string, lld>> name;
while (N--) {
string str;
lld Ai;
cin >> str >> Ai;
name.emplace_back(str, Ai);
}
sort(name.begin(), name.end(), comp);
bool flag = false;
for (lld i = 1; i < name.size() - 1; i++)
if (name[i].second != name[i + 1].second && name[i].second != name[i - 1].second) {
cout << name[i].first << '\n';
flag = true;
break;
}
if (!flag)
cout << "Nobody wins.\n";
}
return 0;
}
My approach:
The approach is simple! I push the names and the called numbers into a vector. I sort it in increasing order. I traverse it again while checking if the numeric element of that index is not equal to the next or the previous one. If so, I output the element.