前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Where's Waldorf?

Where's Waldorf?

作者头像
用户1624346
发布2018-04-11 17:15:41
5750
发布2018-04-11 17:15:41
举报
文章被收录于专栏:calmoundcalmoundcalmound

题意:找相同字符窜首字母的地址

读题。。。。A word matches a straight, uninterrupted line of letters in the grid.The outputs of two consecutive cases will be separated by a blank line.这两句haunted都没读出来。。。。一个说字符窜必须直线,一个说输出在两组数据内,第一个没读导致我用搜索TLE,第二个WA

#include<stdio.h>
#include<string.h>
char str[100][100],rem[100];

int t1[]={-1,-1,-1,0,0,1,1,1};
int t2[]={-1,0,1,-1,1,-1,0,1};
int len,m,n;

void Rever(int row,int col,int ans)
{
    if(str[row][col]>='A' && str[row][col]<='Z') str[row][col]+=32;
    if(rem[ans]>='A' && rem[ans]<='Z') rem[ans]+=32;
}

int Action(int row,int col)
{
    int ans=0,i;
    int x=row,y=col;
    Rever(row,col,ans);
    if(str[row][col]!=rem[ans]) return 0;
    for (i=0;i<8;i++)
    {
        ans=0;
        while(1)
        {
            Rever(row,col,ans);
            if(row<0 || col<0 || row>=m || col>=n || str[row][col]!=rem[ans]) break;
            {
                if(ans==len-1) return 1;
                ans++;
                row+=t1[i];col+=t2[i];
            }
        }
        row=x;col=y;
    }
    return 0;
}

int main()
{
    int i,j;
    int T,x,k;
    int flag;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&m,&n);
        for (i=0;i<m;i++)
        {
            scanf("%s",str[i]);
        }
        scanf("%d",&x);
        for (k=0;k<x;k++)
        {
            scanf("%s",rem);
            len=strlen(rem);
            for (i=0;i<m;i++)
            {
                for (j=0;j<n;j++)
                {
                    flag=0;
                    flag=Action(i,j);
                    if(flag) break;
                }
                if(flag) break;
            }
            printf("%d %d\n",i+1,j+1);
        }
        if(T!=0) printf("\n");
    }
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2012-07-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档