Untitled
unknown
c_cpp
3 years ago
1.6 kB
10
Indexable
#include<bits/stdc++.h>
using namespace std;
int sz=0;
int check=0;
map<int , int> maper;
void preform(string arrays[],int n,string attemt,int start,string outer[]){
if(maper[start]==2){
return;
}
if(check==1){
return;
}
if(start==attemt.length()){
check=1;
return;
}
for(int i = 0;i<n;i++){
string x = arrays[i];
if(x.length()>attemt.length()-start){
continue;
}
string newstr = attemt.substr(start,x.length());
int ns = sz;
if(x.compare(newstr)==0){
outer[sz]=newstr;
sz++;
preform(arrays,n,attemt,start+x.length(),outer);
}
if(check==1){
return;
}
sz=ns;
}
if(check==0){
maper[start]=2;
}
}
int main()
{
int t;
cin>>t;
string out[t];
for (int i = 0;i<t;i++){
string outer[2001];
int n;
cin>>n;
string arrays[n];
for(int j=0;j<n;j++){
cin>>arrays[j];
}
string attempt;
cin>>attempt;
preform(arrays,n,attempt,0,outer);
if(check==1){
for(int j = 0;j<sz-1;j++){
out[i]+=outer[j]+" ";
}
out[i]+=outer[sz-1];
sz=0;
check=0;
maper.clear();
}else{
out[i]="WRONG PASSWORD";
sz=0;
check=0;
maper.clear();
}
}
for(int i = 0;i<t;i++){
cout<<out[i]<<'\n';
}
return 0;
}Editor is loading...