Submission
Status:
[PxSSS][PP-SS]
Subtask/Task Score:
{0/50}{0/50}
Score: 0
User: mightbeputter
Problemset: จุดแวะพัก
Language: cpp
Time: 0.003 second
Submitted On: 2026-03-27 20:20:06
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct hambunger{
int cnt;
string str;
bool operator<(const hambunger &o) const{
if(cnt != o.cnt) return cnt < o.cnt;
for(int i=0;true;i++){
if(str[i] != o.str[i]) return str[i] < o.str[i];
}
}
};
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
string temp;
getline(cin, temp);
int n=0;
string k;
bool ch = 0;
for(auto& x : temp){
if(x == ' '){
ch = true;
continue;
}
if(!ch){
n *= 10;
n += x-'0';
}else{
k.push_back(x);
}
}
vector<hambunger> ans;
for(int i=1;i<=n;i++){
string a, name;
getline(cin, a);
// cout << i << " " << a << "\n";
int cnt = -1, j=0;
for(auto& x : a){
if(x == ' '){
cnt++;
j=0;
continue;
}
if(cnt == -1){
name.push_back(x);
}else if(j != -1){
if(x == k[j]) j++;
else j = -1;
if(j == k.length()) ans.push_back({cnt, name});
}
}
}
sort(ans.begin(), ans.end());
// for(auto& x : ans) cout << x.cnt << " " << x.str << "\n";
cout << ans[0].str << " " << ans[1].str << " " << ans[2].str;
return 0;
}