救命,全tle
查看原帖
救命,全tle
932514
cinema楼主2023/2/12 11:46
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> vars(m);
    int exec_pos = 1;
    while (exec_pos <= n) {
        string type;
        cin >> type;
        if (type == "c") {
            int val;
            cin >> val;
            exec_pos++;
        } else if (type == "v") {
            int var_idx, val;
            char op;
            cin >> var_idx >> op >> val;
            if (op == '+') {
                vars[var_idx] += val;
            } else {
                vars[var_idx] -= val;
            }
            exec_pos++;
        } else if (type == "s") {
            int pos1, pos2;
            cin >> pos1 >> pos2;
            cout << "1" << endl;
            exec_pos = (pos1 > pos2 ? pos1 : pos2);
        } else if (type == "i") {
            int var1, var2, pos1, pos2;
            cin >> var1 >> var2 >> pos1 >> pos2;
            cout << (vars[var1] < vars[var2] ? "1" : "2") << endl;
            exec_pos = (vars[var1] < vars[var2] ? pos1 : pos2);
        }
    }
    return 0;
}
2023/2/12 11:46
加载中...