#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int main()
{
int m, n, count = 0;
cin >> m;
while (cin >> n)
{
cout << "Spreadsheet #" << ++count << endl;
int action, q, row, col;
int target[100][100];
string act[100];
input action part
cin >> action;
for (int i = 0; i < action; i++)
{
cin >> act[i]; // action
if (act[i] == "EX")
{
for (int j = 0; j < 4; j++)
{
cin >> target[i][j];
}
}
else
{
cin >> target[i][0]; // target number
for (int j = 0; j < target[i][0]; j++)
{
cin >> target[i][j + 1];
}
}
}
search part
cin >> q;
for (int ii = 0; ii < q; ii++)
{
int row1, col1;
cin >> row1 >> col1;
row = row1;
col = col1;
for (int i = 0; i < action; i++)
{
if (act[i] == "EX")
{
if (target[i][0] == row && target[i][1] == col)
{
row = target[i][2];
col = target[i][3];
}
else if (target[i][2] == row && target[i][3] == col)
{
row = target[i][0];
col = target[i][1];
}
}
else if (act[i] == "DR")
{
if (row)
{
int sum = 0;
for (int j = 1; j <= target[i][0]; j++)
{
if (target[i][j] < row)
sum++;
else if (target[i][j] == row)
{
row = 0;
col = 0;
break;
}
}
if (row)
row -= sum;
}
}
else if (act[i] == "IR")
{
if (row)
{
int sum = 0;
for (int j = 1; j <= target[i][0]; j++)
{
if (target[i][j] <= row)
sum++;
}
row += sum;
}
}
else if (act[i] == "DC")
{
if (col)
{
int sum = 0;
for (int j = 1; j <= target[i][0]; j++)
{
if (target[i][j] < col)
sum++;
else if (target[i][j] == col)
{
col = 0;
row = 0;
break;
}
}
if (col)
col -= sum;
}
}
else if (act[i] == "IC")
{
if (col)
{
int sum = 0;
for (int j = 1; j <= target[i][0]; j++)
{
if (target[i][j] <= col)
sum++;
}
col += sum;
}
}
}
if (row)
{
cout << "Cell data in (" << row1 << "," << col1 << ") moved to (" << row << "," << col << ")" << endl;
}
else
{
cout << "Cell data in (" << row1 << "," << col1 << ") GONE" << endl;
}
}
cin >> m;
if (m)
cout << endl;
else
break;
}
return 0;
}
UVa 512 - Spreadsheet Tracking
最新推荐文章于 2025-04-26 23:01:23 发布