Submission
Status:
[PPPPP][PPPPP]
Subtask/Task Score:
{50/50}{50/50}
Score: 100
User: kimza
Problemset: จุดแวะพัก
Language: cpp
Time: 0.006 second
Submitted On: 2026-03-05 11:44:01
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n;
string k;
cin >> n >> k;
vector<pair<int,string>> v;
for(int i=0;i<=n;i++){
string s;
getline(cin,s);
stringstream ss(s);
int cnt = -1;
bool isk = false;
bool isf = true; //isfirst
string name;
while(ss>>s){
if(isf){
name = s;
isf = false;
}
if(s==k){
//cout << name << " " << cnt << "\n";
v.push_back({cnt,name});
isk = true;
}
cnt++;
}
if(!isk){
cnt=-1;
}
}
sort(v.begin(),v.end());
if(v.size()==0){
cout << "-1";
}
else if(v.size()<=3 && v.size()>0){
for(int i=0;i<v.size();i++){
cout << v[i].second << " ";
}
}
else if (v.size()>3) {
for(int i=0;i<3;i++){
cout << v[i].second << " ";
}
}
}