-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1203.cpp
49 lines (45 loc) · 1.29 KB
/
P1203.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
#include <iostream>
#include <cstring>
int n;
char string[710] = {0};
int main() {
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> string[i];
string[n+i] = string[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int tmpAns = 0;
char thisColor = string[i];
int ptr = i;
if (thisColor == 'w') {
while (ptr<i+n && (string[ptr] == thisColor || string[ptr] == 'w')) {
ptr++;
tmpAns ++;
}
thisColor = string[ptr];
while (ptr<i+n && (string[ptr] == thisColor || string[ptr] == 'w')) {
ptr++;
tmpAns ++;
}
thisColor = string[ptr];
while (ptr<i+n && (string[ptr] == thisColor || string[ptr] == 'w')) {
ptr++;
tmpAns ++;
}
} else {
while (ptr<i+n && (string[ptr] == thisColor || string[ptr] == 'w')) {
ptr++;
tmpAns ++;
}
thisColor = string[ptr];
while (ptr<i+n && (string[ptr] == thisColor || string[ptr] == 'w')) {
ptr++;
tmpAns ++;
}
}
ans = std::max(ans, tmpAns);
}
std::cout << ans << std::endl;
}