码迷,mamicode.com
首页 > 其他好文 > 详细

uva 10010 - Where's Waldorf?

时间:2015-07-16 02:04:58      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

#include<iostream>
#include<cctype>
#include<algorithm>
using namespace std;

char a[55][55];
string s[22];
int T,m,n,k;

int mx[] = {1, 1, 1, 0, 0, -1, -1, -1};
int my[] = {1, 0, -1, 1, -1, 1, 0, -1};

bool in(int x,int y){
    return x>=1&&x<=m&&y>=1&&y<=n;
}

void getLocation(string s){
    int flag ;

    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j] == tolower(s[0])){
                for(int k = 0; k < 8; k++){
                    flag = 1;
                    int t1 = i,t2 = j;
                    for(int p = 1; p < s.length(); p++){
                        t1 += mx[k];
                        t2 += my[k];
                        if(a[t1][t2] != tolower(s[p]) || !in(t1,t2))
                        {
                            flag = 0;
                            break;
                        }

                    }
                    if(flag){
                        cout << i << " " << j << endl;
                        return;
                    }
                }
            }
        }
    }
}

int main(){
    cin >> T;

    while(T--){
        cin >> m >> n;
        cin.ignore();

        for(int i = 1; i<= m; i++)
            for(int j = 1; j <= n; j++){
                cin >> a[i][j];
                a[i][j] = tolower(a[i][j]);
            }

        cin >> k;
        cin.ignore();

        for(int i = 0; i < k; i++)
            cin >> s[i];
        for(int i = 0; i < k; i++){
            getLocation(s[i]);
        }

        if(T>0)
            cout << endl;
    }

    return 0;
}

 

uva 10010 - Where's Waldorf?

标签:

原文地址:http://www.cnblogs.com/yong-hua/p/4649966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!