-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.cpp
45 lines (45 loc) · 1.09 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<string>vec;
bool constructstring(string target,vector<string>v)
{
if(target.size()==0){
for(int i=0;i<vec.size();i++)cout<<vec[i]<<" "; //prints the construction way
cout<<endl;
vec.pop_back();
return true;
}
for(int i=0;i<v.size();i++){
int found=target.find(v[i]); //finds the word is present in the string or not.
if(found==0){ // checks the word is at the beginning of the string or not
string s;
s=target;
s.erase(0,v[i].size());
vec.push_back(v[i]);
constructstring(s,v);
}
}
vec.pop_back();
return false;
}
int main()
{
string s;
while(1)
{
cin>>s;
int n;
cin>>n;
vector<string>v;
for(int i=0; i<n; i++)
{
string x;
cin>>x;
v.push_back(x);
}
if(constructstring(s,v)==true)cout<<"Yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}