之前
#include <iostream> #include <cstring> #include <cstdio> using namespace std; #define maxn 100 struct command { char opt[5]; int a; int n[maxn]; int r1,r2,c1,c2; }cmd[maxn]; int k; int simulate(int& r0,int& c0); int main() { int kase=0; int r,c; while(scanf("%d%d",&r,&c)==2&&r) { scanf("%d",&k); for(int i=0;i<k;i++) { scanf("%s",cmd[i].opt); if(cmd[i].opt[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].n[j]); } } if(kase) printf("\n"); printf("Spreadsheet #%d\n",++kase); int m; scanf("%d",&m); while(m--) { int r0,c0; 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); } } } int simulate(int& r0,int& c0) { for(int i=0;i<k;i++) { if(cmd[i].opt[0]=='E') { if(cmd[i].r2==r0&&cmd[i].c2==c0) r0=cmd[i].r1,c0=cmd[i].c1; else if(cmd[i].r2==r0&&cmd[i].c2==c0)r0=cmd[i].r2,c0=cmd[i].c2; } else { int dr=0,dc=0; for(int j=0;j<cmd[i].a;j++) { int x=cmd[i].n[j]; if(cmd[i].opt[0]=='D') if(cmd[i].opt[1]=='R') if(x<r0) dr--; else if(x==r0) return 0; else if(x<c0) dc--; else if(x==c0) return 0; else if(x=='R') if(x<=r0) dr++; else if(x<=c0) dc++; } r0+=dr,c0+=dc; } } return 1; }
之后
#include <iostream> #include <cstring> #include <cstdio> using namespace std; #define maxn 100 struct command { char opt[5]; int a; int n[maxn]; int r1,r2,c1,c2; }cmd[maxn]; int k; int simulate(int& r0,int& c0); int main() { int kase=0; int r,c; while(scanf("%d%d",&r,&c)==2&&r) { scanf("%d",&k); for(int i=0;i<k;i++) { scanf("%s",cmd[i].opt); if(cmd[i].opt[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].n[j]); } } if(kase) printf("\n"); printf("Spreadsheet #%d\n",++kase); int m; scanf("%d",&m); while(m--) { int r0,c0; 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); } } } int simulate(int& r0,int& c0) { for(int i=0;i<k;i++) { if(cmd[i].opt[0]=='E') { if(cmd[i].r2==r0&&cmd[i].c2==c0) r0=cmd[i].r1,c0=cmd[i].c1; else if(cmd[i].r1==r0&&cmd[i].c1==c0) r0=cmd[i].r2,c0=cmd[i].c2; } else { int dr=0,dc=0; for(int j=0;j<cmd[i].a;j++) { int x=cmd[i].n[j]; if(cmd[i].opt[0]=='D') if(cmd[i].opt[1]=='R') { if(x<r0) dr--; else if(x==r0) return 0; } else { if(x<c0) dc--; else if(x==c0) return 0; } else { if(cmd[i].opt[1]=='R') { if(x<=r0) dr++; } //大括号一定要加 !!! else { if(x<=c0) dc++; } //大括号一定要加 !!! } } r0+=dr,c0+=dc; } } return 1; }都是花括号的锅...