-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWord_Break_Problem.cpp
More file actions
58 lines (49 loc) · 1.1 KB
/
Word_Break_Problem.cpp
File metadata and controls
58 lines (49 loc) · 1.1 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<string.h>
using namespace std;
bool match(string s)
{
string dictionary[]={ "i","like", "sam" , "sung", "samsung" , "mobile" , "ice", "cream" ,
"icecream" , "man" , "go", "mango"};
int l=sizeof(dictionary)/sizeof(dictionary[0]);
for(int i=0;i<l;i++){
//cout<<dictionary[i]<<endl;
if(s==dictionary[i]){
return true;
}
}
return false;
}
bool match_strings(string s,int i,int j,int l){
string str= s.substr(i,j-i+1);
if( i<l && j<l){
if(match(str)){
if(j==l-1){
return true;
}
return match_strings(s,i+str.length(),++j,l);
}else{
if(j==l-1){
return false;
}
return match_strings(s,i,++j,l);
}
}
}
void repeat(string s,int l)
{
int i=0,j=0;
if(match_strings(s,i,j,l)){
cout<<"True";
}else
cout<<"False";
return;
}
int main(){
cout<<"Enter the string: ";
string s;
cin>>s;
int l=s.length();
repeat(s,l);
return 0;
}