-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreturnSubstring.cpp
More file actions
39 lines (35 loc) · 802 Bytes
/
returnSubstring.cpp
File metadata and controls
39 lines (35 loc) · 802 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
#include<iostream>
#include<fstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<utility>
#include<unordered_map>
#include<set>
#include<map>
#include<unordered_set>
#include<string>
#include<limits.h>
using namespace std;
#define ll long long int
const int mod=1e9+7;
vector<string> getSubstrings(string s) {
//this function takes a string and returns all its substrings
vector<string> substrings;
for (int i = 0; i < s.length(); i++) {
for (int j = 1; j <= s.length() - i; j++) {
string substring = s.substr(i, j);
substrings.push_back(substring);
}
}
for(auto &subs:substrings)
cout<<subs<<"\n";
return substrings;
}
int main()
{
getSubstrings("abcd");
}