Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unordered_map>
- #include <string>
- #include <stdio.h>
- #include <iostream>
- #include<unordered_map>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- unordered_map<int, int> umap;
- int n;
- cin>>n;
- vector< vector<int> > allgroup(n);
- string strs;
- cin>>strs;
- int flag = 0;
- int curchar = 0;
- int getsize = 1;
- for(int i = 0 ; i < n; i++){
- flag = 0;
- if (i == 0){
- umap[i] = 0;
- allgroup[0].push_back((int)strs[i]);
- continue;
- }
- curchar = (int)strs[i];
- // cout<<curchar<<endl;
- for (int j = 0; j < allgroup.size(); j++){
- if (allgroup[j].size() == 0){
- allgroup[j].push_back(curchar);
- umap[i] = j;
- flag = 1;
- break;
- }
- else if (allgroup[j].back() <= curchar){
- allgroup[j].push_back(curchar);
- umap[i] = j;
- flag = 1;
- break;
- }
- }
- // if (flag == 0){
- // getsize++;
- // umap[i] = getsize;
- // allgroup[getsize].push_back((int)strs[i]);
- // }
- }
- int out = 0;
- // cout<<out<<endl;
- for (int i = 0; i < n; i++){
- // cout<<out<<endl;
- out = umap[i] + 1;
- cout<<out;
- if (i != n -1){
- cout<<" ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement