Advertisement
pasholnahuy

reverse prefix func

Sep 28th, 2023
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.     vector<int> pref(n);
  11.     for (int i = 0; i < n; ++i){
  12.         cin >> pref[i];
  13.     }
  14.     char symb = 'a';
  15.     vector<char> s = {'a'};
  16.     for (int i = 1; i < n; ++i){
  17.         if (pref[i] == pref[i-1] + 1){
  18.             s.emplace_back(s[pref[i-1]]);
  19.         } else {
  20.             if (pref[i] == 0){
  21.                 ++symb;
  22.                 s.emplace_back(symb);
  23.             } else {
  24.                 s.emplace_back(s[pref[i]] - 1);
  25.             }
  26.         }
  27.     }
  28.     for (auto el: s){
  29.         cout << el;
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement