Submission

Status:
[PP-SS][PP-SS]

Score: 0

User: FotoFatTurtle

Problemset: จุดแวะพัก

Language: cpp

Time: 0.003 second

Submitted On: 2025-03-19 23:46:14

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int num;
    string want;
    cin>>num>>want;
    vector<pair<int,string>> mar;
    string s,name;
    bool fir;
    int nub=0,nut;
    for(int i=0;i<num;i++)
    {
        getline(cin,s);
        name="";
        fir=false;
        nut=0;
        nub=0;
        for(int j=0;j<s.length();j++)
        {
            if(s[j]==' ')
            {
                fir=true;
                nub++;
                //cout<<i<<" "<<j<<"\n";
                continue;
            }
            if(fir==false)
            {
                name+=s[j];
            }
            else if(s[j]==want[nut])
            {
                nut++;
                if(nut==want.length())
                {
                    mar.push_back({nub,name});
                    break;
                }
            }
            else
            {
                nut=0;
            }
        }
    }
    /*for(int i=0;i<mar.size();i++)
        cout<<mar[i].f<<" "<<mar[i].s<<"\n";*/
    sort(mar.begin(),mar.end());
    //cout<<mar.size()<<" ";
    if(mar.size()==0)
    {
        cout<<"-1";
        return 0;
    }
    nub=0;
    for(int i=0;i<mar.size();i++)
    {
        cout<<mar[i].s<<" ";
        nub++;
        if(nub==3)
            break;
    }
    return 0;
}