2019携程面试题 车辆时刻分组表 (map)

#include
using namespace std;

string s;
map<char, int> ma, cnt;
vector<int> ans;
bool judge(){
    for(auto it:ma)
        if(it.second != cnt[it.first])
            return false;
    return true;
}
int main() {
    cin >> s;
    for(int i = 0; i < s.length(); ++i)
        ++cnt[s[i]];

    for(int i = 0, cur = 0; i < s.length(); ++i){
        ++ma[s[i]], ++cur;
        if(judge()){
            ans.push_back(cur);
            cur = 0;
            ma.clear();
        }
    }
    cout << ans[0];
    for(int i = 1; i < ans.size(); ++i)
        cout << ',' << ans[i];
    cout << endl;

    return 0;
}
/* aabbcddc abcbca abcacb ababaccadd */

算法题需要代写可以私我

你可能感兴趣的:(水题)