Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <unordered_set>
  5. #include <algorithm>
  6.  
  7. const std::string Dict = "abcdefghijklmnopqrstuvwxyz";
  8.  
  9. class Cell {
  10. public:
  11.     char value;
  12.     std::vector<int> not_avalible;
  13. public:
  14.     Cell() = default;
  15.     Cell(const Cell& cell): value(cell.value), not_avalible(cell.not_avalible) {}
  16.     Cell& operator = (const Cell& cell) {
  17.         value = cell.value;
  18.         not_avalible.clear();
  19.         for (auto s: cell.not_avalible) {
  20.             not_avalible.push_back(s);
  21.         }
  22.         return *this;
  23.     }
  24.     ~Cell() = default;
  25. };
  26.  
  27. std::vector<int> Build_Array () noexcept {
  28.     int value;
  29.     std::vector<int> array;
  30.     while (std::cin >> value && value != -1) {
  31.         array.push_back(value);
  32.     }
  33.     return array;
  34. }
  35.  
  36. std::string From_Z_to_String (const std::vector<int>& array) noexcept {
  37.     std::vector<Cell> Struct(array.size());
  38.     std::vector<std::unordered_set<char>> not_char(array.size());
  39.     Struct[0].value = 'a';
  40.     for (int i = 1; i < array.size(); ++i) {
  41.         if (array[i] != 0) {
  42.             int count = array[i];
  43.             int head = 0;
  44.             Struct[array[i] + i].not_avalible.push_back(array[i]);
  45.             while (count != 0 && array[i + head] <= count) {
  46.                 Struct[i + head].value = Struct[head].value;
  47.                 for (int k = i + head + 1; k < array.size(); ++k) {
  48.                     if (std::find(Struct[k].not_avalible.begin(), Struct[k].not_avalible.end(), i + head) != Struct[k].not_avalible.end()) {
  49.                         not_char[k].insert(Struct[i + head].value);
  50.                     }
  51.                 }
  52.                 --count;
  53.                 ++head;
  54.             }
  55.             i = i + head - 1;
  56.            
  57.         }
  58.         else {
  59.             not_char[i].insert('a');
  60.             for (int j = 0; j < Dict.size(); ++j) {
  61.                 if (not_char[i].find(Dict[j]) == not_char[i].end()) {
  62.                     Struct[i].value = Dict[j];
  63.                     break;
  64.                 }
  65.             }
  66.         }
  67.     }
  68.     std::string answer;
  69.     for (auto cell: Struct) {
  70.         answer += cell.value;
  71.     }
  72.     return answer;
  73. }
  74.  
  75. int main() {
  76.    
  77.     std::vector<int> array = Build_Array();
  78.    
  79.     std::cout << From_Z_to_String(array) << '\n';
  80.    
  81.    
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement