Question
Simulation questions are also a variety of Wa. Recently I have fallen, and, IQ is getting negative !!!!!!!!
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char mp[10][10];int d=-1;//0shang,1xia,2zuo,3youint x,y;//weizhiint weizhi(int i,int j){ if(mp[i][j]==‘<‘){x=i,y=j,d=2;return 1;} if(mp[i][j]==‘>‘){x=i,y=j,d=3;return 1;} if(mp[i][j]==‘^‘){x=i,y=j,d=0;return 1;} if(mp[i][j]==‘v‘){x=i,y=j,d=1;return 1;} return 0;}void fangxiang(){ if(d==0)mp[x][y]=‘^‘; else if(d==1)mp[x][y]=‘v‘; else if(d==2)mp[x][y]=‘<‘; else if(d==3)mp[x][y]=‘>‘;}void mov(int num){ while(num--) { char fro=mp[x][y]; if(d==0) { for(int i=x-1;i>=0;i--){ if(mp[i][y]==‘.‘){mp[i][y]=fro;break;} else { char tmp=mp[i][y]; mp[i][y]=fro; fro=tmp; } } if(x-1>=0)mp[x][y]=‘.‘,x--; } else if(d==1){ for(int i=x+1;i<8;i++){ if(mp[i][y]==‘.‘){mp[i][y]=fro;break;} else { char tmp=mp[i][y]; mp[i][y]=fro; fro=tmp; } } if(x+1<8)mp[x][y]=‘.‘,x++; } else if(d==2){ for(int i=y-1;i>=0;i--){ if(mp[x][i]==‘.‘){mp[x][i]=fro;break;} else { char tmp=mp[x][i]; mp[x][i]=fro; fro=tmp; } } if(y-1>=0)mp[x][y]=‘.‘,y--; } if(d==3){ for(int i=y+1;i<8;i++){ if(mp[x][i]==‘.‘){mp[x][i]=fro;break;} else { char tmp=mp[x][i]; mp[x][i]=fro; fro=tmp; } } if(y+1<8) mp[x][y]=‘.‘,y++; } }}void turnn(char cc){ if(cc==‘l‘) { if(d==0)d=2; else if(d==1)d=3; else if(d==2)d=1; else if(d==3)d=0; } else if(cc==‘r‘) { if(d==0)d=3; else if(d==1)d=2; else if(d==2)d=0; else if(d==3)d=1; } else if(cc==‘b‘) { if(d==0)d=1; else if(d==1)d=0; else if(d==2)d=3; else if(d==3)d=2; }}int main(){ while(scanf("%s",mp[0])!=EOF) { if(strcmp(mp[0],"--")==0)break; for(int i=1;i<8;i++) { scanf("%s",mp[i]); } int fl=0; for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ if(weizhi(i,j)){fl=1;break;} } if(fl)break; } while(1) { char p[10]; int movee; scanf("%s",p); if(strcmp(p,"#")==0)break; if(strcmp(p,"move")==0){ scanf("%d",&movee); mov(movee); } else { scanf("%s",p); turnn(p[0]); fangxiang(); } } for(int i=0;i<8;i++) printf("%s\n",mp[i]); printf("\n"); } return 0;}
View code
HDU 2414 chessboard Dance (simulation question, only to commemorate my fall)