Advertisement
Mirbek

Untitled

Jun 6th, 2022
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int a, b, c, d, e;
  7.     cin >> a >> b >> c >> d >> e;
  8.  
  9.     string s, s1[7005], s2[7005];
  10.     int n = 0;
  11.  
  12.     while (cin >> s) {
  13.         n++;
  14.         s1[n] = s;
  15.         if (s == "MOV") {
  16.             cin >> s2[n];
  17.         }
  18.         if (s == "XCHG") {
  19.             cin >> s2[n];
  20.         }
  21.         if (s == "LOOP") {
  22.             cin >> s2[n];
  23.         }
  24.         if (s == "EXIT") {
  25.            break;
  26.         }
  27.     }
  28.  
  29.     map <string, int> mp;
  30.     map <char, int> rg;
  31.  
  32.     for (int i = 1; i <= n; i++) {
  33.         if (s1[i][0] == ':') {
  34.             mp[s1[i]] = i;
  35.         }
  36.     }
  37.  
  38.     long long ans = 0;
  39.  
  40.     for (int i = 1; i <= n; i++) {
  41.         if (s1[i] == "LOOP") {
  42.             ans += c;
  43.         }
  44.         if (s1[i] == "LOOP" && rg['C'] > 0) {
  45.             i = mp[':' + s2[i]];
  46.             rg['C']--;
  47.         }
  48.         if (s1[i] == "MOV") {
  49.             ans += a;
  50.             char rgA = s2[i][0];
  51.             if (isdigit(s2[i][2])) {
  52.                 int num = 0;
  53.                 for (int j = 2; j < s2[i].size(); j++) {
  54.                     num *= 10;
  55.                     num += s2[i][j] - '0';
  56.                 }
  57.                 rg[rgA] = num;
  58.             } else {
  59.                 char rgB = s2[i][2];
  60.                 rg[rgA] = rg[rgB];
  61.             }
  62.         }
  63.         if (s1[i] == "XCHG") {
  64.             ans += b;
  65.             char rgA = s2[i][0];
  66.             char rgB = s2[i][2];
  67.             swap(rg[rgA], rg[rgB]);
  68.         }
  69.         if (s1[i] == "NOP") ans += d;
  70.         if (s1[i] == "EXIT") ans += e;
  71.     }
  72.  
  73.     cout << ans << endl;
  74. }
  75.  
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement