-
Notifications
You must be signed in to change notification settings - Fork 2
/
zagrade.cpp
85 lines (74 loc) · 1.84 KB
/
zagrade.cpp
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
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#define EPSILON 0.00001
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll i, j, k;
ll parenLoc;
stack<ll> parenStack;
vector<pair<ll, ll> > parenPairs;
string originalString;
string expressionString;
set<string> uniqueExpressions;
cin >> originalString;
for(i = 0; i < originalString.size(); i++)
{
if (originalString[i] == '(')
{
parenStack.push(i);
}
else if (originalString[i] == ')')
{
parenLoc = parenStack.top();
parenStack.pop();
parenPairs.push_back(make_pair(parenLoc, i));
}
}
for(i = 1; i < pow(2, parenPairs.size()); i++)
{
vector<bool> usedParenLocs;
usedParenLocs.resize(originalString.size(), true);
expressionString.clear();
for(j = 0; j < parenPairs.size(); j++)
{
if((i >> j)&1)
{
usedParenLocs[parenPairs[j].first] = false;
usedParenLocs[parenPairs[j].second] = false;
}
}
for(j = 0; j < originalString.size(); j++)
{
if(usedParenLocs[j])
{
expressionString.push_back(originalString[j]);
}
}
uniqueExpressions.insert(expressionString);
}
for(auto expression : uniqueExpressions)
{
cout << expression << "\n";
}
return 0;
}