Advertisement
pasholnahuy

обратная префикс функция

Sep 28th, 2023
1,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 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] == 0) {
  18.             ++symb;
  19.             s.emplace_back(symb);
  20.         } else {
  21.             s.emplace_back(s[pref[i-1]]);
  22.         }
  23.     }
  24.     for (auto el: s){
  25.         cout << el;
  26.     }
  27.     return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement