MIST-National Collegiate Programming Contest, 2020 Problem B Search The Files Solution
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,n,i,j,ts,k,f;
vector<int>v;
cin>>t;
for(ts=1; ts<=t; ts++)
{
string s1,target;
v.clear();
cin>>n;
string sa[n+1];
for(i=0; i<n; i++)
cin>>sa[i];
cin>>target;
int m=target.size();
for(k=0; k<n; k++)
{
string s1=sa[k];
int l=s1.size();
int j=0;
for (int i = 0; i < l && j< m; i++)
{
if (s1[i]== target[j])
{
j++;
}
}
if(j == m)
v.push_back(k);
}
printf("Case %d:\n",ts);
int vs=v.size();
if(vs>0)
{
for(i=0; i<vs; i++)
{
if(i+1==vs)
cout<<v[i]+1<<endl;
else
cout<<v[i]+1<<" ";
}
}
else
cout<<"No files found!"<<endl;
}
}
No comments