无语,一开始结构体里面用的不是数组是vector,但是不知道为啥就是过不了,换了数组就过了,现在还不明白。
然后这道题有两种思路,一种就是先模拟完所有的操作,第二种就是先把操作寸起来,输入一个查询模拟一个,第一种还没有写过,直接按第二种思路来写的
这道题的插入删除操作,是一系列同时完成的,不是一个一个做的,
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
struct record {
string op;
int v[20], num;
} rec[10005];
int main() {
int r, c;
int z = 0;
while (cin >> r >> c) {
if (!r && !c) break;
int num;
cin >> num;
for (int i = 0; i < num; i++) {
string s;
cin >> s;
rec[i].op = s;
if (s == "EX") {
for (int j = 0; j < 4; j++) {
cin >> rec[i].v[j];
}
} else {
cin >> rec[i].num;
for (int j = 0; j < rec[i].num; j++) {
cin >> rec[i].v[j];
}
}
}
int q;
cin >> q;
int x, y;
if (z++) printf("\n");
printf("Spreadsheet #%d\n", z);
while (q--) {
cin >> x >> y;
printf("Cell data in (%d,%d) ", x, y);
int ok = 0;
for (int i = 0; i < num; i++) {
if (rec[i].op == "EX") {
int r1 = rec[i].v[0], c1 = rec[i].v[1];
int r2 = rec[i].v[2], c2 = rec[i].v[3];
if (r1 == x && c1 == y) {
x = r2;
y = c2;
} else if (r2 == x && c2 == y) {
x = r1;
y = c1;
}
} else {
int m1 = 0, m2 = 0;
int e1 = 0, e2 = 0;
for (int j = 0; j < rec[i].num; j++) {
int t = rec[i].v[j];
if (t <= x) m1++;
if (t <= y) m2++;
if (t == x) e1 = 1;
if (t == y) e2 = 1;
}
if (rec[i].op == "DR") {
if (e1) {
ok = 1;
break;
} else x -= m1;
} else if (rec[i].op == "DC") {
if (e2) {
ok = 1;
break;
} else y -= m2;
} else if (rec[i].op == "IR") x += m1;
else if (rec[i].op == "IC") y += m2;
}
}
if (ok) printf("GONE\n");
else printf("moved to (%d,%d)\n", x, y);
}
}
return 0;
}