Submission
Status:
[P-SSS][-SSSS]
Subtask/Task Score:
{0/50}{0/50}
Score: 0
User: goine
Problemset: จุดแวะพัก
Language: cpp
Time: 0.011 second
Submitted On: 2026-02-04 13:26:56
#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
int main() {
int count, target;
cin >> count >> target;
cin.ignore(); // eat newline
unordered_map<string, int> mp;
for (int i = 0; i < count; i++) {
string s;
getline(cin, s);
stringstream ss(s);
string key;
ss >> key;
int x;
int pos = 0;
while (ss >> x) {
pos++;
if (x == target) {
mp[key] = pos;
break;
}
}
}
// move to vector so we can sort
vector<pair<string, int>> v(mp.begin(), mp.end());
sort(v.begin(), v.end(),
[](const pair<string, int>& a, const pair<string, int>& b) {
if (a.second == b.second)
return a.first < b.first;
return a.second < b.second;
}
);
for (const auto& p : v) {
cout << p.first << ' ';
}
return 0;
}