版权声明: https://blog.csdn.net/a673953508/article/details/81086329
题解:
题目大意为 你输入几个操作,改变该表格。然后输入原来的几个点,输出改变之后的位置或者gone(已被删除)
直接操作表格比较难写,所以思想就是先把操作和原来的点想记录下来;
然后判断每个点经过每个操作后的位置。书上都写了这两种方法。我的做法是第二个
#include <bits/stdc++.h>
using namespace std;
struct Node{ //保存一开始的点数
int r;
int c;
}node[100];
string opera[500];
void exope(int tim,int n){ //开始对第n个点进行t次操作
int isdel = 0; //判断是否被del了
for(int i = 0; i < tim; i++){
stringstream ss(opera[i]);
string tmp;
ss >> tmp;
if(!tmp.compare("DC") || !tmp.compare("DR")){
int tno;
if(tmp[1] == 'C') tno = node[n].c;
else tno = node[n].r;
int dell,isjud = tno; //jud是保存没改变之前r或者c的数据,dell则是要删除的r、c
ss >> dell; //去掉第一个
while(ss >> dell){
if(dell == isjud){ isdel = 1; break; }
else if(dell < isjud) tno--;
}
if(tmp[1] == 'C') node[n].c = tno;
else node[n].r = tno;
}else if(!tmp.compare("IC") || !tmp.compare("IR")){
int tno;
if(tmp[1] == 'C') tno = node[n].c;
else tno = node[n].r;
int dell,isjud = tno;
ss >> dell; //去掉第一个
while(ss >> dell){
if(dell <= isjud) tno++;
}
if(tmp[1] == 'C') node[n].c = tno;
else node[n].r = tno;
}else{
int r1,c1,r2,c2;
ss >> r1 >> c1 >> r2 >> c2;
if(node[n].r == r1 && node[n].c == c1){
node[n].r = r2; node[n].c = c2;
} else if(node[n].r == r2 && node[n].c == c2){
node[n].r = r1; node[n].c = c1;
}
}
}
if(isdel) printf("GONE\n");
else printf("moved to (%d,%d)\n",node[n].r,node[n].c);
}
int main() {
//freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int rnd = 1;
int curr,curc; //一开始的行和列
while(scanf("%d%d",&curr,&curc) == 2 && curr){
int ope;
scanf("%d",&ope);
getchar();
for(int i = 0; i < ope; i++){
getline(cin,opera[i]);
}
int dnum;
scanf("%d",&dnum);
for(int i = 0; i < dnum; i++){
scanf("%d%d",&node[i].r,&node[i].c);
} //到这里为止前面是为了记录所有操作和点数
if(rnd != 1) printf("\n");
printf("Spreadsheet #%d\n",rnd++);
for(int i = 0; i < dnum; i++){
printf("Cell data in (%d,%d) ",node[i].r,node[i].c);
exope(ope,i);
}
}
return 0;
}