题解 P7262 【Get Your Wish】

· · 题解

这是一道并不复杂的模拟题

来说说思路

由于本题的数据量很小( 1≤n,m≤100 ),所以就可以用暴力的方法来愉快地通过这道题啦!

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;
}