例题4-5
https://vjudge.net/problem/UVA-512
#include<iostream>
#include<string>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;
struct node {
int hang,lie;
bool is_die = false;
};
node all[55][55];
int r, c;
string s;
node t1, t2;
int vis[55];
int main() {
int cnt = 0;
while (cin >> r >> c && (r || c)) {
if (cnt) printf("\n");
printf("Spreadsheet #%d\n", ++cnt);
int n, m, x;
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j)
all[i][j].hang = i, all[i][j].lie = j,all[i][j].is_die=false;
cin >> n;
while (n--) {
cin >> s;
switch (s[0] * 1000 + s[1])
{
case 'E' * 1000 + 'X':
cin >> t2.hang >> t2.lie >> t1.hang >> t1.lie;
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j) {
if (!all[i][j].is_die && all[i][j].hang == t1.hang && all[i][j].lie == t1.lie)
all[i][j].hang = t2.hang, all[i][j].lie = t2.lie;
else if (!all[i][j].is_die && all[i][j].hang == t2.hang && all[i][j].lie == t2.lie)
all[i][j].hang = t1.hang, all[i][j].lie = t1.lie;
}
break;
case 'D' * 1000 + 'R':
cin >> m;
memset(vis, 0, sizeof(vis));
while (m--) {
cin >> x;
++vis[x];
}
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j)
if (!all[i][j].is_die && vis[all[i][j].hang]) all[i][j].is_die = true;
for (int i = 1; i <= 50; ++i)
vis[i] += vis[i - 1];
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j)
if (!all[i][j].is_die) all[i][j].hang -= vis[all[i][j].hang];
break;
case 'D'*1000 + 'C':
cin >> m;
memset(vis, 0, sizeof(vis));
while (m--) {
cin >> x;
++vis[x];
}
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j)
if (!all[i][j].is_die && vis[all[i][j].lie]) all[i][j].is_die = true;
for (int i = 1; i <= 50; ++i)
vis[i] += vis[i - 1];
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j)
if (!all[i][j].is_die) all[i][j].lie -= vis[all[i][j].lie];
break;
case 'I' * 1000 + 'R':
cin >> m;
memset(vis, 0, sizeof(vis));
while (m--) { cin >> x; ++vis[x]; }
for (int i = 1; i <= 50; ++i)
vis[i] += vis[i - 1];
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j)
if (!all[i][j].is_die) all[i][j].hang += vis[all[i][j].hang];
break;
case 'I' * 1000 + 'C':
cin >> m;
memset(vis, 0, sizeof(vis));
while (m--) { cin >> x; ++vis[x]; }
for (int i = 1; i <= 50; ++i)
vis[i] += vis[i - 1];
for (int i = 1; i <= r; ++i)
for (int j = 1; j <= c; ++j)
if (!all[i][j].is_die) all[i][j].lie += vis[all[i][j].lie];
break;
default:
break;
}
}
cin >> n;
while (n--) {
cin >> r >> c;
if (all[r][c].is_die) printf("Cell data in (%d,%d) GONE\n", r, c);
else printf("Cell data in (%d,%d) moved to (%d,%d)\n", r, c, all[r][c].hang, all[r][c].lie);
}
}
}