第一次使用讨论版,请见谅orz
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int R,C,OR,OC;
int N,M,spreadsheet;
int x,y,t;
char s[100];
int command[100];
vector<int> a[100];
void DC(int t)
{
for(int k=1;k<=t;k++)
{
command[k]=command[k]-k+1;
for(int i=1;i<=R;i++)
a[i].erase(a[i].begin()+command[k]);
}
}
void DR(int t)
{
for(int k=1;k<=t;k++)
{
command[k]=command[k]-k+1;
for(int i=command[k]+1;i<=R;i++)
for(int j=1;j<=C;j++)
a[i-1][j]=a[i][j];
}
}
void IC(int t)
{
for(int k=1;k<=t;k++)
{
command[k]=command[k]+k-1;
for(int i=1;i<=R;i++)
a[i].insert(a[i].begin()+command[k],0);
}
}
void IR(int t)
{
for(int k=1;k<=t;k++)
{
command[k]=command[k]+k-1;
for(int i=R+1;i>command[k];i--)
for(int j=1;j<=C;j++)
a[i][j]=a[i-1][j];
for(int i=1;i<=C;i++)
a[command[k]][i]=0;
R++;
}
}
int main()
{
freopen("ST.in","r",stdin);
freopen("ST.out","w",stdout);
while(cin>>R>>C&&!(R==0&&C==0))
{
cout<<"Speadsheet #"<<++spreadsheet<<endl;
OR=R,OC=C;
for(int i=0;i<100;i++)
a[i].clear();
for(int i=0;i<=R;i++)
{
for(int j=0;j<=C;j++)
{
if(i==0||j==0)
a[i].push_back(0);
else
a[i].push_back((i-1)*C+j);
}
}
for(int i=R+1;i<100;i++)
{
for(int j=0;j<=C;j++)
a[i].push_back(0);
}
cin>>N;
for(int k=1;k<=N;k++)
{
cin>>s;
if(s[0]=='E'&&s[1]=='X')
{
memset(command,0,sizeof(command));
cin>>command[1]>>command[2]>>command[3]>>command[4];
swap(a[command[1]][command[2]],a[command[3]][command[4]]);
}
if(s[0]=='D'&&s[1]=='C')
{
memset(command,0,sizeof(command));
cin>>t;
for(int i=1;i<=t;i++)
cin>>command[i];
sort(command+1,command+t+1);
DC(t);
C-=t;
}
if(s[0]=='D'&&s[1]=='R')
{
memset(command,0,sizeof(command));
cin>>t;
for(int i=1;i<=t;i++)
cin>>command[i];
sort(command+1,command+t+1);
DR(t);
R-=t;
}
if(s[0]=='I'&&s[1]=='C')
{
memset(command,0,sizeof(command));
cin>>t;
for(int i=1;i<=t;i++)
cin>>command[i];
sort(command+1,command+t+1);
IC(t);
C+=t;
}
if(s[0]=='I'&&s[1]=='R')
{
memset(command,0,sizeof(command));
cin>>t;
for(int i=1;i<=t;i++)
cin>>command[i];
sort(command+1,command+t+1);
IR(t);
}
}
/*
cout<<R<<" "<<C<<endl;
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
printf("%5d",a[i][j]);
cout<<endl;
}
*/
cin>>N;
for(int k=1;k<=N;k++)
{
cin>>x>>y;
cout<<"Cell data in ("<<x<<","<<y<<") ";
t=(x-1)*OC+y;
//cout<<t<<endl;
int flag=0;
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
{
if(t==a[i][j])
{
cout<<"moved to ("<<i<<","<<j<<")"<<endl;
flag=1;
break;
}
}
}
if(flag==0)
cout<<"GONE"<<endl;
}
cout<<endl;
}
return 0;
}