题解 P7262 【Get Your Wish】
这是一道并不复杂的模拟题
来说说思路
-
开一个二维字符数组,存储这个二维平面
-
遍历整个字符数组,如果发现水滴,就按照方向去寻找有无关键电子元件,找到后立刻 return 0
由于本题的数据量很小(
Code:
#include<bits/stdc++.h>
using namespace std;
char c[105][105];
int main(){
int n,m;
cin>>n>>m;
char to;
cin>>to;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>c[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(c[i][j]=='o'){
if(to=='^'){//向上
int t=i;
while(t>=0){
if(c[t][j]=='x'){
cout<<"GG";
return 0;
}
t--;
}
}
if(to=='v'){//向下
int t=i;
while(t<=n){
if(c[t][j]=='x'){
cout<<"GG";
return 0;
}
t++;
}
}
if(to=='<'){//向左
int t=j;
while(t>=0){
if(c[i][t]=='x'){
cout<<"GG";
return 0;
}
t--;
}
}
if(to=='>'){//向右
int t=j;
while(t<=m){
if(c[i][t]=='x'){
cout<<"GG";
return 0;
}
t++;
}
}
}
}
}
cout<<"OK";
return 0;
}