模拟 + 二维数组
2023-08-22 14:43:48
发布于:上海
4阅读
0回复
0点赞
#include<iostream>
using namespace std;
int n,m;
bool in_mp(int x,int y){
return x>=0 && x<n && y>=0 && y<m;
}
int main(){
cin>>n>>m;
int x=0,y=0;
char mp[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>mp[i][j];
}
}
string do_it;
cin>>do_it;
for(int i=0;i<do_it.size();i++){
if(do_it[i]=='R'){
if(!in_mp(x,y+1)){
cout<<"NO Way!"<<endl;
continue;
}
y++;
if(mp[x][y]=='X'){
cout<<"I Can do win!";
}
else{
cout<<"I Can";
}
cout<<endl;
continue;
}
if(do_it[i]=='L'){
if(!in_mp(x,y-1)){
cout<<"NO Way!"<<endl;
continue;
}
y--;
if(mp[x][y]=='X'){
cout<<"I Can do win!";
}
else{
cout<<"I Can";
}
cout<<endl;
continue;
}
if(do_it[i]=='T'){
if(!in_mp(x-1,y)){
cout<<"NO Way!"<<endl;
continue;
}
x--;
if(mp[x][y]=='X'){
cout<<"I Can do win!";
}
else{
cout<<"I Can";
}
cout<<endl;
continue;
}
if(do_it[i]=='D'){
if(!in_mp(x+1,y)){
cout<<"NO Way!"<<endl;
continue;
}
x++;
if(mp[x][y]=='X'){
cout<<"I Can do win!";
}
else{
cout<<"I Can";
}
cout<<endl;
continue;
}
}
return 0;
}
这里空空如也
有帮助,赞一个