Submission

Status:
[P-SSS][-SSSS]

Score: 0

User: AungS8430

Problemset: จุดแวะพัก

Language: cpp

Time: 0.012 second

Submitted On: 2025-03-16 09:39:26

#include <bits/stdc++.h>
#include <sstream>
using namespace std;

typedef struct VISITOR {
  string name;
  int time;
  bool operator<(VISITOR &v) {
    if (v.time == time) return strcmp(name.c_str(), v.name.c_str()) < 0;
    else return time < v.time;
  }
} visitor;

int main(void) {
  int n, k;
  string temp;
  cin >> n >> k;
  vector<visitor> v;
  cin.ignore();
  for (int i = 0; i < n; i++) {
    getline(cin, temp);
    stringstream ss(temp);
    string name;
    string stops;
    int count = 0;
    ss >> name;
    while (ss >> stops) {
      count++;
      if (stoi(stops) == k) {
        visitor c;
        c.name = name;
        c.time = count;
        v.push_back(c);
        break;
      }
    }
  }
  sort(v.begin(), v.end());
  for (visitor c : v) {
    cout << c.name << " ";
  }
  return 0;
}