Code: Select all
#include<iostream>
#include<vector>
using namespace std;
typedef struct
{
int i, j;
}item;
int main()
{
int n, m, o, x = 1, z, val;
int x1, y1, x2, y2;
string s;
do
{
cin >> n >> m;
if(n!=0&&m!=0)
{
if(x>1)cout << endl;
vector< vector<item> > v(n+1, vector<item>(m+1));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
v[i][j].i = i;
v[i][j].j = j;
}
cin >>o;
while(o--)
{
cin >> s;
if(s=="DR")
{
cin >> z;
for (int i = 0; i < z; i++)
{
cin >> val;
v.erase(v.begin() + val - i);
n--;
}
}
else if(s=="DC")
{
cin >> z;
for (int i = 0; i < z; i++)
{
cin >> val;
for (int j = 1; j <= n; j++)
v[j].erase(v[j].begin()+val-i);
m--;
}
}
else if(s=="IC")
{
item aux;
aux.i = aux.j = -1;
cin >> z;
for (int i = 0; i < z; i++)
{
cin >> val;
for (int j = 1; j <= n; j++)
v[j].insert(v[j].begin()+val+i, aux);
m++;
}
}
else if(s=="IR")
{
item aux;
aux.i = aux.j = -1;
cin >> z;
for (int i = 0; i < z; i++)
{
cin >> val;
vector<item> vaux(m+1, aux);
v.insert(v.begin()+val+i, vaux);
n++;
}
}
else if(s=="EX")
{
cin >> x1 >> y1 >> x2 >> y2;
item aux;
aux.i = v[x1][y1].i;
aux.j = v[x1][y1].j;
v[x1][y1].i=v[x2][y2].i;
v[x1][y1].j=v[x2][y2].j;
v[x2][y2].i=aux.i;
v[x2][y2].j=aux.j;
}
}
/*for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
cout << "(" << v[i][j].i << ", " << v[i][j].j << ") ";
cout << endl;
}*/
cout << "Spreadsheet #" << x++ << endl;
cin >> o;
int xi, yj, i, j;
while(o--)
{
cin >> xi >> yj;
i=1;
bool cond = false;
while(i <= n && !cond)
{
j=1;
while(j<=m && !cond)
{
cond = v[i][j].i==xi&&v[i][j].j==yj;
if(!cond)j++;
}
if(!cond) i++;
}
cout << "Cell data in (" << xi << "," << yj << ") ";
if(cond) cout << "moved to (" << i << "," << j << ")" << endl;
else cout << "GONE" << endl;
}
}
}while(n!=0&&m!=0);
return 0;
}