Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
111240 | 朱悦晨 | 划分字母区间 | C++ | 通过 | 100 | 0 MS | 252 KB | 739 | 2023-11-19 13:42:42 |
#include <bits/stdc++.h> using namespace std; string S; vector<int> fg() { int hash[27] = {0}; // i为字符,hash[i]为字符出现的最后位置 for (int i = 0; i < S.size(); i++) { // 统计每一个字符最后出现的位置 hash[S[i] - 'a'] = i; } vector<int> result; int left = 0; int right = 0; for (int i = 0; i < S.size(); i++) { right = max(right, hash[S[i] - 'a']); // 找到字符出现的最远边界 if (i == right) { result.push_back(right - left + 1); left = i + 1; } } return result; } int main(){ cin>>S; vector<int> r = fg(); for(int i=0;i<r.size();i++) cout<<r[i]<<" "; return 0; }