Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <unordered_set>
- #include <algorithm>
- const std::string Dict = "abcdefghijklmnopqrstuvwxyz";
- class Cell {
- public:
- char value;
- std::vector<int> not_avalible;
- public:
- Cell() = default;
- Cell(const Cell& cell): value(cell.value), not_avalible(cell.not_avalible) {}
- Cell& operator = (const Cell& cell) {
- value = cell.value;
- not_avalible.clear();
- for (auto s: cell.not_avalible) {
- not_avalible.push_back(s);
- }
- return *this;
- }
- ~Cell() = default;
- };
- std::vector<int> Build_Array () noexcept {
- int value;
- std::vector<int> array;
- while (std::cin >> value && value != -1) {
- array.push_back(value);
- }
- return array;
- }
- std::string From_Z_to_String (const std::vector<int>& array) noexcept {
- std::vector<Cell> Struct(array.size());
- std::vector<std::unordered_set<char>> not_char(array.size());
- Struct[0].value = 'a';
- for (int i = 1; i < array.size(); ++i) {
- if (array[i] != 0) {
- int count = array[i];
- int head = 0;
- Struct[array[i] + i].not_avalible.push_back(array[i]);
- while (count != 0 && array[i + head] <= count) {
- Struct[i + head].value = Struct[head].value;
- for (int k = i + head + 1; k < array.size(); ++k) {
- if (std::find(Struct[k].not_avalible.begin(), Struct[k].not_avalible.end(), i + head) != Struct[k].not_avalible.end()) {
- not_char[k].insert(Struct[i + head].value);
- }
- }
- --count;
- ++head;
- }
- i = i + head - 1;
- }
- else {
- not_char[i].insert('a');
- for (int j = 0; j < Dict.size(); ++j) {
- if (not_char[i].find(Dict[j]) == not_char[i].end()) {
- Struct[i].value = Dict[j];
- break;
- }
- }
- }
- }
- std::string answer;
- for (auto cell: Struct) {
- answer += cell.value;
- }
- return answer;
- }
- int main() {
- std::vector<int> array = Build_Array();
- std::cout << From_Z_to_String(array) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement