uva 512

</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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值