Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
133932 | baim. | 划分字母区间 | C++ | 通过 | 100 | 0 MS | 248 KB | 583 | 2024-03-02 10:45:06 |
#include <bits/stdc++.h> using namespace std; vector<int> partitionLabels(string S) { vector<int> ans,ends(26, -1); for (int i = 0; i < S.length(); ++i) { ends[S[i] - 'a'] = i; } int i = 0; while (i < S.size()) { int r = ends[S[i] - 'a']; for (int j = i + 1; j <= r; ++j) { r = max(r, ends[S[j] - 'a']); } ans.push_back(r - i + 1); i = r + 1; } return ans; } int main() { string s; cin >> s; vector<int> a = partitionLabels(s); for (vector<int>::iterator it = a.begin(); it != a.end(); ++it) { cout << *it << " "; } return 0; }