UVA 10010 - Where's Waldorf? 水题一道

因为数据量小   所以直接枚举所有情况   不会超时

#include<cstdio>
#include<cstring>
#include<cctype>

int dir_x[8]={-1,-1,-1,0,0,1,1,1};//定义方向增量
int dir_y[8]={-1,0,1,-1,1,-1,0,1};

int main()
{
    #ifdef LOCAL
    freopen("in.txt","r",stdin);
    #endif // LOCAL
    int N,m,n,k,X,Y;
    scanf("%d",&N);
    while(N--)
    {
        scanf("%d%d",&m,&n);
        getchar();
        char str[m+5][n+5];
        int i,j;
        for(i = 0; i < m ;i++)
            gets(str[i]);
        for(i = 0; i < m; i++)
            for(j = 0; j < n; j++)
            if(isalpha(str[i][j])) str[i][j] = toupper(str[i][j]);//小写转换成大写
        scanf("%d",&k);
        getchar();
        char s[55];
        for(i = 0; i < k ; i++)
        {
            scanf("%s",s);
            int len_s = strlen(s);
            for(j = 0; j < len_s; j++)
            if(isalpha(s[j])) s[j] = toupper(s[j]);//小写转换成大写
            int ok[8],flag = 0;
            for(int x = 0; x < m && !flag; x++)
                for(int y = 0; y < n && !flag; y++)//枚举每一个字母
            {
                if(str[x][y]!=s[0])continue;
                for(int q = 0 ; q < 8; q++) ok[q] = 1;
                for(int l = 0; l < 8; l++)//匹配每个方向的字母
                {
                    for(j = 1; j < len_s; j++)
                        if(str[x+dir_x[l]*j][y+dir_y[l]*j]!=s[j])
                            {ok[l] = 0;break;}//当前方向不满足条件了就结束
                }
                for(j = 0; j < 8; j++)
                if(ok[j]){flag = 1; X = x+1; Y = y+1; break;}//只要有一个ok到最后的值还是一就满足
            }
            printf("%d %d\n",X,Y);
        }
        if(N!=0)printf("\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值