Precreation contest files
This commit is contained in:
45
misc/chuyen-de-xau/b2.cpp
Normal file
45
misc/chuyen-de-xau/b2.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int segn[300];
|
||||
|
||||
int main() {
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
for (int j = 0; j < 300; j++)
|
||||
segn[j] = 0;
|
||||
string S;
|
||||
cin >> S;
|
||||
const int n = S.length();
|
||||
int res1 = 0;
|
||||
int res2 = 0;
|
||||
|
||||
int l = 0, r = 1;
|
||||
int i = 0;
|
||||
while (r < n) {
|
||||
if (S[l] == S[r])
|
||||
r++;
|
||||
else {
|
||||
segn[i] = r - l;
|
||||
l = r;
|
||||
r++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
segn[i] = r - l;
|
||||
i++;
|
||||
|
||||
for (int k = 0; k < i; k++) {
|
||||
res1 = max(res1, segn[k]);
|
||||
if (segn[k + 1] == 1) {
|
||||
res2 = max(res2, segn[k] + segn[k + 1] + segn[k + 2]);
|
||||
}
|
||||
if (k != 0 || k != n - 1) {
|
||||
res2 = max(res2, segn[k] + 1);
|
||||
}
|
||||
}
|
||||
cout << res1 << '\n';
|
||||
cout << res2 << '\n';
|
||||
}
|
||||
Reference in New Issue
Block a user