-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubPermutations.cpp
More file actions
53 lines (46 loc) · 1.07 KB
/
subPermutations.cpp
File metadata and controls
53 lines (46 loc) · 1.07 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <queue>
int main(int argc, char const *argv[])
{
const char *s = "abbc";
const char *b = "cbabadcbbabbcdabaabccbabc";
std::map<char, int> dic;
std::queue<char> indexes;
const int sl = strlen(s), bl = strlen(b);
for(int i=0; i<sl; ++i){
if(!dic.count(s[i]))
dic[s[i]] = 1;
else
dic[s[i]]++;
}
for(int j = 0; j<bl-3; ++j){
char i = b[j];
std::map<char, int> tmp(dic);
int c = 0;
bool keep = true;
while(keep && c<sl){
i = b[j+c];
if(tmp.count(i) && tmp[i]>0){
tmp[i]--;
keep = true;
c++;
}
else
keep = false;
}
if(c == sl)
indexes.push(j);
}
printf("Permutations found at: ");
while(indexes.size()){
const int v = indexes.front();
printf("%d, ", v);
indexes.pop();
}
printf("\n");
/* code */
return 0;
}