code:
#include<stdio.h> #include<string.h> #define maxd 10000 //#define LOCAL // A structure contains: command, point before and now, // the number of changed lines, the c\r index. struct Command { char c[5]; int r1, c1, r2, c2; int a, x[20]; }cmd[maxd]; int r, c, n; //a fuction be used to change the query(previous) point to the present point. //CMD: EX(only one) DC\R IC\R(lots of lines) int simulate(int &r0, int &c0) { for( int i = 0; i < n; i++) { int nr(0), nc(0); //to count the change number. if( cmd[i].c[0] == 'E' ) { if( cmd[i].r1 == r0 && cmd[i].c1 == c0 ){ r0 = cmd[i].r2; c0 = cmd[i].c2;} else if( cmd[i].r2 == r0 && cmd[i].c2 == c0 ){ r0 = cmd[i].r1; c0 = cmd[i].c1;} } //judge the Delete or Insert. else { if(cmd[i].c[0] == 'D') { for(int j = 0; j < cmd[i].a; j++) { //DC if( cmd[i].c[1] == 'C' ) { if( cmd[i].x[j] == c0 ) return 0; if( cmd[i].x[j] < c0 ) nc--; } //DR else { if( cmd[i].x[j] == r0 ) return 0; if( cmd[i].x[j] < r0 ) nr--; } } } //IC/IR else { for( int j = 0; j < cmd[i].a; j++) { //IC if( cmd[i].c[1] == 'C') { if ( cmd[i].x[j] <= c0 ) nc++; } //IR else { if ( cmd[i].x[j] <= r0 ) nr++; } } } } r0 += nr; c0 += nc; } return 1; } int main() { #ifdef LOCAL freopen("data.in", "r", stdin); freopen("data.out", "w", stdout); #endif int r0, c0, q, kase = 0; while(scanf("%d%d%d", &r, &c, &n) == 3 && r) { //We need the i to record the index. for(int i = 0; i < n; i++) { scanf("%s", cmd[i].c); //CMD: EX DC\R IC\R if(cmd[i].c[0] == 'E') { scanf("%d%d%d%d", &cmd[i].r1, &cmd[i].c1, &cmd[i].r2, &cmd[i].c2); } else { scanf("%d", &cmd[i].a); for(int j = 0; j < cmd[i].a; j++) { scanf("%d", &cmd[i].x[j]); } } } if(kase > 0) printf("\n"); printf("Spreadsheet #%d\n", ++kase); scanf("%d", &q); //the format while(q--) { scanf("%d%d", &r0, &c0); printf("Cell data in (%d,%d) ", r0, c0); if(!simulate(r0, c0)) printf("GONE\n"); else printf("moved to (%d,%d)\n", r0, c0); } } return 0; }
- 特别要注意if的连用问题,比如在情况EX里面 如果连个都写的是If, 那么会有有趣的事情发生, 两个数字换过去,竟然又换回来了,真的是很神奇。解决的方案也比较简单使用else if即可。
- < and <=的使用要注意,因为这里比较隐蔽,很容易出现WA,而不知道哪里错了,因此在每次做题目的时候出现问题,需要在所有的判断处检查一下
- . and ,因为这两个字符在键盘上的位置离得比较近,有的时候容易手误打错了,可是编译器有的时候不一定会报错,它可能会认为是逗号运算符就放过去了。