Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int a, b, c, d, e;
- cin >> a >> b >> c >> d >> e;
- string s, s1[7005], s2[7005];
- int n = 0;
- while (cin >> s) {
- n++;
- s1[n] = s;
- if (s == "MOV") {
- cin >> s2[n];
- }
- if (s == "XCHG") {
- cin >> s2[n];
- }
- if (s == "LOOP") {
- cin >> s2[n];
- }
- if (s == "EXIT") {
- break;
- }
- }
- map <string, int> mp;
- map <char, int> rg;
- for (int i = 1; i <= n; i++) {
- if (s1[i][0] == ':') {
- mp[s1[i]] = i;
- }
- }
- long long ans = 0;
- for (int i = 1; i <= n; i++) {
- if (s1[i] == "LOOP") {
- ans += c;
- }
- if (s1[i] == "LOOP" && rg['C'] > 0) {
- i = mp[':' + s2[i]];
- rg['C']--;
- }
- if (s1[i] == "MOV") {
- ans += a;
- char rgA = s2[i][0];
- if (isdigit(s2[i][2])) {
- int num = 0;
- for (int j = 2; j < s2[i].size(); j++) {
- num *= 10;
- num += s2[i][j] - '0';
- }
- rg[rgA] = num;
- } else {
- char rgB = s2[i][2];
- rg[rgA] = rg[rgB];
- }
- }
- if (s1[i] == "XCHG") {
- ans += b;
- char rgA = s2[i][0];
- char rgB = s2[i][2];
- swap(rg[rgA], rg[rgB]);
- }
- if (s1[i] == "NOP") ans += d;
- if (s1[i] == "EXIT") ans += e;
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement