-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (80 loc) · 1.69 KB
/
Copy pathmain.cpp
File metadata and controls
87 lines (80 loc) · 1.69 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// Created by silverstringer on 06.05.19.
//
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
vector<string> res;
bool test_sequency(const char *str) {
stack<int> stack;
while (*str) {
if (*str == '(') {
stack.push(0);
} else {
if (*str == ')') {
if (stack.empty())
return false;
else
stack.pop();
}
}
++str;
}
return stack.empty();
}
void gen_resurc_sequen(const char* pIn, int N, int K)
{
if(K == 0){
return;
}
char* pOut = new char[K + 1];
pOut[K] = 0;
K--;
int *stack = new int[K * 2],
*pTop = stack,
k = 0,
n = 0,
j = 0;
for (;;)
{
while(n < N) {
pOut[k] = pIn[n++];
if (k == K) {
if (test_sequency(pOut))
res.push_back(pOut);
}
else
{
if (n < N)
{
*pTop++ = k;
*pTop++ = n;
}
k++;
n = 0;
}
}
if (pTop == stack)
break;
n = *(--pTop);
k = *(--pTop);
}
delete[] pOut;
delete[] stack;
return;
}
int main()
{
int n;
cin >> n;
const char *s="()";
// clock_t start = clock();
gen_resurc_sequen(s,2,2*n);
// clock_t end = clock();
// double seconds = (double)(end - start) / CLOCKS_PER_SEC;
// cout<<"The time: seconds\n"<<seconds;
for (int i = 0; i < res.size(); i++)
std::cout << res[i] << "\n";
return 0;
}