刚刚结束的阿里笔试QAQ
我来了...
第一题是签到题,确实就是脑子清楚就能做,大概就是给你方向,不碰壁,不到尽头可以一直走~
#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; }
第二题看了其他人发的,好像是dpQAQ,哎好菜