-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringPopping_UVA1261.cpp
78 lines (65 loc) · 1.48 KB
/
stringPopping_UVA1261.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
#include <bits/stdc++.h>
using namespace std;
ifstream fin("stringPopping_UVA1261.in");
ofstream fout("stringPopping_UVA1261.out");
struct g
{
char ch;
int size;
};
int main()
{
int testCase; fin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
string in; fin >> in;
char last = in[0];
int sizeI = in.size(), _count = 1;
vector<g> s;
for (int i = 1; i <= sizeI; ++i)
{
if (in[i] != last)
{
g temp{last, _count};
s.push_back(temp);
last = in[i];
_count = 1;
}
else
{
++_count;
}
}
int n = s.size();
while (true)
{
bool ok = false;
for (int i = 1; i <= n - 2; ++i)
{
if (s[i - 1].ch == s[i + 1].ch)
{
ok = true;
}
s[i - 1].size += s[i + 1].size;
s.erase(s.begin() + i); s.erase(s.begin() + i);
}
if (ok == false)
{
break;
}
}
if (s.size() > 1)
{
fout << "0\n";
}
else if (s[0].size <= 1)
{
fout << "0\n";
}
else
{
fout << "1\n";
}
}
return 0;
}