NCPC 2020 – Search The Files

Problem NameSearch The Files
JudgeCodeMarshal
Problem Linkhttps://algo.codemarshal.org/contests/mist-ncpc-2020/problems/B
Algorithms & DSAdhoc, Sorting
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ll t;
    cin>>t;
    ll n;
    for(ll T=1;T<=t;T++){
        cin>>n;
        vector<string>st;
        string s;
        for(ll i=0;i<n;i++){
            cin>>s;
            st.push_back(s);
        }
        string pat;
        cin>>pat;
        vector<ll>ans;
        ll pat_len=pat.size();
        for(ll i=0;i<n;i++){
            ll pat_ct=0;
            s=st[i];
            ll s_len=s.size();
            for(ll j=0;j<s_len;j++){
                if(pat_ct>=pat_len)break;
                if(pat[pat_ct]==s[j])pat_ct++;
            }
            if(pat_ct>=pat_len)ans.push_back(i+1);
        }
        cout<<"Case "<<T<<":\n";
        ll ans_len=ans.size();
        for(ll i=0;i<ans_len;i++){
            if(i!=0)cout<<" ";
            cout<<ans[i];
        }
        if(ans_len==0)cout<<"No files found!";
        cout<<"\n";
    }

    return 0;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
error: Alert: Content is protected !!