-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_substring.cpp
More file actions
41 lines (35 loc) · 837 Bytes
/
Copy pathcheck_substring.cpp
File metadata and controls
41 lines (35 loc) · 837 Bytes
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
#include<iostream>
using namespace std;
bool sub_check( string s, string sub){
int s1 = s.size();
int s2 = sub.size();
for (int i = 0; i <= (s1-s1); i++){
if (s[1]==sub[0]){
bool flag=true;
for (int j=i; j<=(i+s2); j++){
if (s[j]!=sub[j-i]){
bool flag=false;
break;
}
}
if (flag){
return true;
}
}
}
return false;
}
int main(){
string str, sub;
cout<<"Enter a string: ";
cin>>str;
cout<<"Enter a sub-string: ";
cin>>sub;
if (sub_check(str, sub)){
cout<<"A sub-string found in the main string.";
}
else{
cout<<"No sub-string found!";
}
return 0;
}