</pre><pre name="code" class="cpp">#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <list>
using namespace std;
const int MAXN = 100;
const int base = 10000;
typedef long long LL;
typedef list<string> COL;
/*
关键: 1. 只需int类型存储单元格, 单元格的值存储初始行数和列数, 用 r*base+c来表示
2. 行数和列数用全局变量表示, 省去函数间传参与返回
3. 移动行或者列时, 用一个临时表来存储 , 作为中介
4. 所要操作行,列的传递可以直接用一个一维全局数组变量来传递, 这样就省去了传递数组指针和数组大小的麻烦
*/
int ans[MAXN][MAXN], sheet[MAXN][MAXN], tmp[MAXN][MAXN];
int r,c;
int targets[MAXN];
void copy(char type, int from, int to){
if( type=='R' ){
for(int i=1; i<=c; i++){
sheet[to][i] = tmp[from][i];
}
}else{
for(int i=1; i<=r; i++){
sheet[i][to] = tmp[i][from];
}
}
}
void del(char type){
memcpy(tmp,sheet,sizeof(sheet));
int cnt = 0;
int n = ( type=='R'? r : c );
for(int i=1; i<=n; i++){
if( !targets[i] ){
copy(type, i, ++cnt);
}
}
if( type=='R' ){
r = cnt;
}else{
c = cnt;
}
}
void ins(char type){
memcpy(tmp,sheet,sizeof(sheet));
int cnt = 0;
int n = ( type=='R'? r : c );
for(int i=1; i<=n; i++){
if( targets[i] ){
copy(type,0,++cnt);
}
copy(type,i,++cnt);
}
if( type=='R' ){
r = cnt;
}else{
c = cnt;
}
}
void test(){
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
printf("%5d ",sheet[i][j]);
}
printf("\n");
}
return ;
}
int main(){
scanf("%d %d",&r,&c);
int Case = 0;
while( !(r==0 || c==0) ){
Case++;
int n;
char cmd[10];
memset(sheet,0,sizeof(sheet));
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
sheet[i][j] = i*base + j;
}
}
scanf("%d",&n);
while( n-- ){
scanf("%s",cmd);
if( cmd[0]=='E' ){
int r1,r2,c1,c2;
scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
int tmp = sheet[r1][c1];
sheet[r1][c1] = sheet[r2][c2];
sheet[r2][c2] = tmp;
}else{
memset(targets,0,sizeof(targets));
int tgs = 0, tg;
scanf("%d",&tgs);
if( cmd[0]=='D' ){
while( tgs-- ){
scanf("%d",&tg);
targets[tg] = 1;
}
del(cmd[1]);
}else if( cmd[0]=='I' ){
while( tgs-- ){
scanf("%d",&tg);
targets[tg] = 1;
}
ins(cmd[1]);
}
}
// 操作完成 , 把ans填充好, 其中ans的下标是原来的位置, 其值为现在的位置
}
for( int i=1; i<=r; i++){
for( int j=1; j<=c; j++){
ans[(sheet[i][j]/base)][(sheet[i][j]%base)] = i*base+j;
}
}
int ops=0,r1,c1;
printf("Spreadsheet #%d\n",Case);
scanf("%d",&ops);
while( ops-- ){
scanf("%d %d",&r1,&c1);
printf("Cell data in (%d,%d) ",r1,c1);
int val = ans[r1][c1];
if( val==0 ){
printf("GONE\n");
}else{
printf("moved to (%d,%d)\n",val/base,val%base);
}
}
scanf("%d %d",&r,&c);
}
return 0;
}
uva 512
最新推荐文章于 2021-02-02 21:31:30 发布