题意: 模拟文档的操作,增加删除,最后查询初始单元格的位置。
不需要每次都变,直接在询问的时候模拟过程就好。不是很复杂。
但是今天不知道怎么回事,老是出一些奇怪的错误…废了很长时间。哎。
#include <bits/stdc++.h>
using namespace std;
#define maxn 60
int m,n;
struct p
{
int way;
int n;
int r1,c1,r2,c2;
int a[15];
p(int a,int b)
{ way = a; n = b; }
p(){}
}op[100005];
int main()
{
//freopen("D:\\in.txt","r",stdin);
int onum,qnum;
int t = 1;
while(~scanf("%d%d",&m,&n) && m)
{
scanf("%d",&onum);
for(int i = 0; i < onum; i++)
{
char s[5];
int a;
scanf("%s",s);
scanf("%d",&a);
op[i].n = a;
if(s[0] == 'D' && s[1] == 'R')
op[i].way = 1;
else if(s[0] == 'D' && s[1] == 'C')
op[i].way = 2;
else if(s[0] == 'I' && s[1] == 'R')
op[i].way = 3;
else if(s[0] == 'I' && s[1] == 'C')
op[i].way = 4;
else
op[i].way = 5;
if(op[i].way == 5)
{
op[i].r1 = a;
scanf("%d%d%d",&op[i].c1,&op[i].r2,&op[i].c2);
}
else
{
for(int j = 0; j < a; j++)
scanf("%d",&op[i].a[j]);
}
}
scanf("%d",&qnum);
if(t!=1)
printf("\n");
printf("Spreadsheet #%d\n",t++);
while(qnum--)
{
int a,b;
scanf("%d%d",&a,&b);
int ansa = a,ansb = b;
int flag = 1;
for(int i = 0; i < onum; i++)
{
if(op[i].way == 1)
{
int temp = 0;
for(int j = 0; j < op[i].n; j++)
{
if(op[i].a[j] == ansa)
{ flag = 0; break;}
else if(op[i].a[j] < ansa)
temp++;
}
ansa -= temp;
}
else if(op[i].way == 2)
{
int temp = 0;
for(int j = 0; j < op[i].n; j++)
{
if(op[i].a[j] == ansb)
{
ansb = -1; flag = 0;break;
}
else if(op[i].a[j] < ansb)
temp ++;
}
ansb -= temp;
}
else if(op[i].way == 3)
{
int temp = 0;
for(int j = 0; j < op[i].n; j++)
{
if(op[i].a[j] <= ansa)
temp++;
}
ansa += temp;
}
else if(op[i].way == 4)
{
int temp = 0;
for(int j = 0; j < op[i].n; j++)
{
if(op[i].a[j] <= ansb)
temp++;
}
ansb += temp;
}
else
{
if(op[i].r1 == ansa && op[i].c1 == ansb)
ansa = op[i].r2,ansb = op[i].c2;
else if(op[i].r2 == ansa && op[i].c2 == ansb)
ansa = op[i].r1,ansb = op[i].c1;
}
if(flag == 0) break;
}
if(!flag)
printf("Cell data in (%d,%d) GONE\n",a,b);
else
{
printf("Cell data in (%d,%d) moved to (%d,%d)\n",a,b,ansa,ansb);
}
}
}
return 0;
}