第一题就是不到头不碰比一起走~
#include<iostream> #include<cstring> #include<string.h> #include<iomanip> using namespace std; int main() { int n,m,k;//行,列,几次 int hang = 0; int lie = 0; cin>>n>>m>>k; char map[1020][1020]={'0'}; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin>>map[i][j]; if(map[i][j] == '@') { hang = i; lie = j; } } } int d[1020] = {0}; int temp = 1; int k1 = k; while(k1--) { char c[7];//方位暂存 cin>>c[0]; if(c[0]=='E') { d[temp++] = 1;//判东 cin>>c[1]>>c[2]>>c[3]; } else if(c[0]=='S') { d[temp++] = 2;//判南 cin>>c[1]>>c[2]>>c[3]>>c[4]; } else if(c[0]=='W') { d[temp++] = 3;//判西 cin>>c[1]>>c[2]>>c[3]; } else if(c[0]=='N') { d[temp++] = 4;//判北 cin>>c[1]>>c[2]>>c[3]>>c[4]; } } for(int i = 1; i <= k; i++) { if(d[i] == 1) { while(map[hang][lie+1] != '#'&&lie<m) { lie++; } } if(d[i] == 2) { while(map[hang+1][lie] != '#'&&hang<n) { hang++; } } if(d[i] == 3) { while(map[hang][lie-1] != '#'&&lie>1) { lie--; } } if(d[i] == 4) { while(map[hang-1][lie] != '#'&&hang>1) { hang--; } } } cout<<hang<<" "<<lie<<endl; return 0; }第二题就没有然后了QAQ,果然签到完了就走
全部评论
(2) 回帖