Advertisement
aayyk

Untitled

May 26th, 2022
639
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void write_sample(const string& s, map<int, char>& chars) {
  5. }
  6.  
  7. signed main() {
  8.     freopen("program.in", "r", stdin);
  9.  
  10.     const int max_states = 228;
  11.     const int max_actions = 1488;
  12.  
  13.     map<int, char> chars;
  14.     map<pair<int, char>, tuple<int, char, int>> prog;
  15.     set<int> states;
  16.     int actions = 0;
  17.  
  18.     write_sample("00111000", chars);
  19.  
  20.     int cur_st, new_st, shift;
  21.     char cur_ch, new_ch;
  22.  
  23.     while (cin >> cur_st) {
  24.         cin >> cur_ch >> new_st >> new_ch >> shift;
  25.         prog[{ cur_st, cur_ch }] = { new_st, new_ch, shift };
  26.     }
  27.  
  28.     int state = 1, pos = 0;
  29.     while (state != 0) {
  30.         if (!chars.count(pos)) {
  31.             chars[pos] = '!';
  32.         }
  33.  
  34.         assert(prog.count({ state, chars[state] })); // netu perehoda
  35.  
  36.         auto [new_st, new_ch, shift] = prog[{ state, chars[pos] }];
  37.  
  38.         chars[pos] = new_ch;
  39.         state = new_st;
  40.         pos += shift;
  41.  
  42.         states.insert(state);
  43.         ++actions;
  44.  
  45.         assert(states.size() <= max_states);
  46.         assert(actions <= max_actions);
  47.     }
  48.  
  49.     string ans;
  50.     while (chars.count(pos) && chars[pos] != '!') {
  51.         ans += chars[pos];
  52.         ++pos;
  53.     }
  54.  
  55.     cout << ans << endl;
  56.  
  57.     return 0;
  58. }
Advertisement
RAW Paste Data Copied
Advertisement