-
Notifications
You must be signed in to change notification settings - Fork 0
/
208A - Dubstep.cpp
76 lines (66 loc) · 1.43 KB
/
208A - Dubstep.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
std::vector<std::string> res;
string trm(string s)
{
int index = 0;
for (int i = 0; i < s.length() - 2; i += 3)
if (s[i] == 'W' && s[i + 1] == 'U' && s[i + 2] == 'B')
index += 3;
else
return s.substr(index);
return s.substr(index);
}
int next(string s)
{
for (int i = 0; i < (int)s.length() - 2; i++)
{
if (s[i] == 'W' && s[i + 1] == 'U' && s[i + 2] == 'B')
return i;
}
return -1;
}
void calc(std::string s)
{
s = trm(s);
// cout << s << '\n';
// exit(0);
int co = 0;
while (s.length() != 0)
{
co++;
s = trm(s);
// if(co == 3) {cout << s << '\n'; exit(0);}
if (s.length() == 0)
return;
int index = next(s);
// if(co == 3){cout << index << '\n'; exit(0);}
// exit(0);
if (index == -1)
{
res.push_back(s);
return;
}
else
{
res.push_back(s.substr(0, index));
s = s.substr(index, s.length() - index);
// if(co == 2){cout << s << '\n';exit(0);}
// exit(0);
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
string s;
cin >> s;
calc(s);
for (auto i : res)
cout << i << ' ';
cout << '\n';
return EXIT_SUCCESS;
}