水题
感觉操作数组删行添行比较麻烦
可以把操作步骤存储下来, 每次搜索时逐步操作即可
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 60;
struct command{
char c[5]; //操作名称
int t;
int mrk[100];
};
int main()
{
int a,b;
int num = 0;
struct command com[100];
while( scanf("%d%d",&a,&b) && a )
{
if(++num != 1) puts("");
printf("Spreadsheet #%d
",num);
int T;
scanf("%d",&T);
for( int i = 0; i < T; i++ )
{
scanf("%s",com[i].c);
if( com[i].c[0] == 'E' ){
com[i].t = 4;
for( int j = 0; j < com[i].t; j++ )
scanf("%d",&com[i].mrk[j]);
}
else{
scanf("%d",&com[i].t);
for( int j = 0; j < com[i].t; j++ )
scanf("%d",&com[i].mrk[j]);
}
}
int TT;
scanf("%d",&TT);
int x, y;
while( TT-- )
{
scanf("%d%d",&x,&y);
int x0 = x, y0 = y;
for( int i = 0; i < T; i++ )
{
int sum = 0;
if( com[i].c[0] == 'E' ){
if( ( x == com[i].mrk[0] && y == com[i].mrk[1] ) ){
x = com[i].mrk[2];
y = com[i].mrk[3];
}
else if( ( x == com[i].mrk[2] && y == com[i].mrk[3] ) ){
x = com[i].mrk[0];
y = com[i].mrk[1];
}
}
if( strcmp( com[i].c, "DR" ) == 0 ){
for( int j = 0; j < com[i].t; j++ ){
if( x > com[i].mrk[j] ) sum++;
else if( x == com[i].mrk[j] ) sum = x;
}
x -= sum;
if( x <= 0 ) break;
}
if( strcmp( com[i].c, "DC" ) == 0 ){
for( int j = 0; j < com[i].t; j++ ){
if( y > com[i].mrk[j] ) sum++;
else if( y == com[i].mrk[j] ) sum = y;
}
y -= sum;
if( y <= 0 ) break;
}
if( strcmp( com[i].c, "IR" ) == 0 ){
for( int j = 0; j < com[i].t; j++ )
if( x >= com[i].mrk[j] ) sum++;
x += sum;
}
if( strcmp( com[i].c, "IC" ) == 0 ){
for( int j = 0; j < com[i].t; j++ )
if( y >= com[i].mrk[j] ) sum++;
y += sum;
}
}
printf("Cell data in (%d,%d) ",x0,y0);
if( x <= 0 || y <= 0 ) puts("GONE");
else printf("moved to (%d,%d)
",x,y);
}
}
return 0;
}