Guest User

Turing

a guest
Apr 3rd, 2015
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. //http://www.reddit.com/r/dailyprogrammer/comments/31aja8/20150403_challenge_208_hard_the_universal_machine/
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <set>
  6. #include <map>
  7. #include <queue>
  8. #include <stack>
  9. #include <string>
  10. #include <utility>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <sstream>
  14. using namespace std;
  15.  
  16. typedef long long ll;
  17. typedef vector<int> VI;
  18. typedef vector<VI> VVI;
  19. typedef vector<ll> VL;
  20. typedef vector<VL> VVL;
  21. typedef vector<char> VC;
  22. typedef vector<string> VS;
  23. typedef pair<int, int> P;
  24. typedef pair<string, char> PSC;
  25. typedef pair<int, P> PP;
  26. typedef vector<P> VP;
  27. typedef vector<PP> VPP;
  28. typedef pair<PSC, int> PSCI;
  29. typedef map<PSC, PSCI> M;
  30. typedef M::iterator MIT;
  31. #define pb push_back
  32. #define X first
  33. #define Y second
  34. #define L(v) (int)v.size()
  35.  
  36.  
  37.  
  38.  
  39. int main() {
  40.     string alphabet;
  41.     cin >> alphabet;
  42.     string s;
  43.     cin >> s;
  44.     getline(cin, s);
  45.     string actual;
  46.     cin >> actual;
  47.     string accepted;
  48.     cin >> accepted;
  49.     string word;
  50.     cin >> word;
  51.     string a;
  52.     M conditions;
  53.     while (cin >> a) {
  54.         char c;
  55.         cin >> c;
  56.         char igual;
  57.         cin >> igual;
  58.         string res;
  59.         cin >> res;
  60.         char def;
  61.         cin >> def;
  62.         char pos;
  63.         cin >> pos;
  64.         int x;
  65.         if (pos == '<') x = -1;
  66.         else x = 1;
  67.         conditions[PSC(a,c)] = PSCI(PSC(res,def),x);
  68.     }
  69.    
  70.     int i = 0;
  71.     while (actual != accepted) {
  72.         char c;
  73.         if (i >= 0 and i < L(word)) c = word[i];
  74.         else c = '_';
  75.         PSC f = PSC(actual, c);
  76.         MIT it = conditions.find(f);
  77.         actual = it->Y.X.X;
  78.         if (i >= 0 and i < L(word)) {
  79.             char def = it->Y.X.Y;
  80.             word[i] = def;
  81.             i += it->Y.Y;
  82.         }
  83.         else if (i >= L(word)) {
  84.             char def = it->Y.X.Y;
  85.             if (def != '_') word += def;
  86.             i += it->Y.Y;
  87.         }
  88.         else {
  89.             char def = it->Y.X.Y;
  90.             if (def != '_') {
  91.                 string p = word;
  92.                 word = def;
  93.                 word += p;
  94.             }
  95.             i += it->Y.Y;
  96.         }
  97.     }
  98.     cout << word << endl;
  99.     cout << "|";
  100.     if (i == 0) cout << endl;
  101.     else {
  102.         i--;
  103.         for (int j = 0; j < i; ++j) cout << " ";
  104.         cout << "^" << endl;
  105.     }
  106.    
  107. }
Add Comment
Please, Sign In to add comment