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 19:52:49

#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);
    int n;
    string k;
    cin >> n >> k;
    string useless;
    getline(cin, useless);
    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;
}