Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
过了的朋友能帮我看看吗?代码风格良好:)#include <iostream> using namespace std; struct Robert { int c,r; int num; int dir; }; struct Order { int re; int Rnum; char T; }; Robert R[110]; Order O[110]; int sto[150][150]; int n,m; int p,q; void Read() { cin>>n>>m; cin>>p>>q; char tmp; for (int i=1;i<=p;i++) { cin>>R[i].c; cin>>R[i].r; sto[R[i].r][R[i].c]=i; cin>>tmp; int z; switch (tmp) { case 'N': { z=0; break; } case 'W': { z=1; break; } case 'S': { z=2; break; } case 'E': { z=3; break; } } R[i].dir=z; } for (int i=1;i<=q;i++) { cin>>O[i].Rnum; cin>>O[i].T; cin>>O[i].re; } } void solve() { int Rnum; char Ac; int re; for (int i=1;i<=q;i++) { Rnum=O[i].Rnum; Ac=O[i].T; re=O[i].re; for (int k=1;k<=re;k++) { switch (Ac) { case 'L': { R[Rnum].dir=(R[Rnum].dir-1+4)%4; break; } case 'R': { R[Rnum].dir=(R[Rnum].dir+1)%4; break; } case 'F': { int COL,ROW; sto[R[Rnum].r][R[Rnum].c]=0; if (R[Rnum].dir==0) { ROW=R[Rnum].r-1; COL=R[Rnum].c; } else if (R[Rnum].dir==1) { ROW=R[Rnum].r; COL=R[Rnum].c-1; } else if (R[Rnum].dir==2) { ROW=R[Rnum].r+1; COL=R[Rnum].c; } else if (R[Rnum].dir==3) { ROW=R[Rnum].r; COL=R[Rnum].c+1; } R[Rnum].r=ROW; R[Rnum].c=COL; if (ROW<=0||ROW>m||COL<=0||COL>n) { cout<<"Robot "<<Rnum<<" crashes into the wall"<<endl; return ; } if (sto[ROW][COL]!=0) { cout<<"Robot "<<Rnum<<" crashes into robot "<<sto[ROW][COL]<<endl; return ; } sto[ROW][COL]=Rnum; break; } } } } cout<<"OK"<<endl; } int main() { int T; cin>>T; while (T--) { memset(sto,0,sizeof(sto)); Read(); solve(); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator