-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path753.cpp
More file actions
105 lines (83 loc) · 1.42 KB
/
753.cpp
File metadata and controls
105 lines (83 loc) · 1.42 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*****************************************
* (This comment block is added by the Judge System)
* Submission ID: 68632
* Submitted at: 2018-10-26 17:57:54
*
* User ID: 539
* Username: 55211931
* Problem ID: 753
* Problem Name: Amazing Tree
*/
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
class c {
public:
char label;
int pos;
c(char l, int p)
{
label = l;
pos = p;
}
};
int calcu(string T) {
if (T == "()")
{
return 1;
}
else
{
for (int i = 0; i < T.size() - 1; i++)
{
if (T.at(i) == '('&&T.at(i + 1) == ')')
{
T.erase(i, 2);
return 1 + calcu(T);
}
}
return 0;
}
}
int main()
{
string s;
while (cin >> s)
{
vector<int> times;
list<c> temp;
while (!s.empty())
{
temp.push_back(c(s.at(0), 0));
int pos = 1;
int last;
while (!temp.empty())
{
if (s.at(pos) == ')')
{
temp.pop_back();
last = pos;
}
else
{
temp.push_back(c(s.at(pos), pos));
}
pos++;
}
string thesub = s.substr(0, last);
times.push_back(1+calcu(thesub));
s.erase(s.begin()+last);
s.erase(s.begin());
}
int xVal = times.front();
for (int i = 1; i < times.size(); i++)
{
xVal = xVal ^ times.at(i);
}
cout << xVal << endl;
}
return 0;
}