some programs!

This commit is contained in:
rogerwang2008 committed 2026-09-25 20:20:01 +08:00
1 parent 5d30e847c1
commit ed054247d5
32 files changed
+1882 -149

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#include <cstring>
#include <iostream>
using namespace std;
constexpr int MAX_N = 1e6 + 5;
int max_period[MAX_N];
void log_array(const int arr[], const size_t n) {
for (size_t i = 0; i < n; i++) {
clog << arr[i] << " ";
}
clog << endl;
}
void solve(string s) {
memset(max_period, 0, sizeof(max_period));
max_period[0] = 1;
for (int i = 1; i < s.size(); i++) {
if (s[i - max_period[i - 1]] == s[i]) {
max_period[i] = max_period[i - 1];
} else {
max_period[i] = i + 1;
}
}
log_array(max_period, s.size());
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
while (cin >> n && n) {
cin >> s;
solve(s);
}
return 0;
}