• UVa-Where's Waldorf?


    题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=951&mosmsg=Submission+received+with+ID+12045188

    忒恶心了,UVa不提示格式错误,格式错误直接WA。。。

    C++代码:

    #include <cstdio>
    #include <utility>
    #include <cstring>
    using namespace std;
    char s[100][100];
    int m,n;
    int len;
    bool searchright(int a,int b,char name[])
    {
    	int i=a,j=b;
    	if(b+len-1>=n)
    		return false;
    	for(;j<=b+len-1;++j)
    		if(s[i][j]!=name[j-b])
    			return false;
    	return true;
    }
    bool searchleft(int a,int b,char name[])
    {
    	int i=a,j=b;
    	if(b-len+1<0)
    		return false;
    	for(;j>=b-len+1;--j)
    		if(s[i][j]!=name[b-j])
    			return false;
    	return true;
    }
    bool searchup(int a,int b, char name[])
    {
    	int i=a,j=b;
    	if(a-len+1<0)
    		return false;
    	for(;i>=a-len+1;--i)
    		if(s[i][j]!=name[a-i])
    			return false;
    	return true;
    }
    bool searchdown(int a,int b, char name[])
    {
    	int i=a,j=b;
    	if(a+len-1>=m)
    		return false;
    	for(;i<=a+len-1;++i)
    		if(s[i][j]!=name[i-a])
    			return false;
    	return true;
    }
    bool searchleftup(int a,int b,char name[])
    {
    	int i=a,j=b;
    	if((i-len+1<0)||(j-len+1<0))
    		return false;
    	for(;i>=a-len+1;--i,--j)
    		if(s[i][j]!=name[a-i])
    			return false;
    	return true;
    }
    bool searchrightup(int a,int b,char name[])
    {
    	int i=a,j=b;
    	if((i-len+1<0)||(b+len-1>=n))
    		return false;
    	for(;i>=a-len+1;--i,++j)
    		if(s[i][j]!=name[a-i])
    			return false;
    	return true;
    }
    bool searchleftdown(int a,int b,char name[])
    {
    	int i=a,j=b;
    	if((i+len-1>=m)||(j-len+1<0))
    		return false;
    	for(;i<=a+len-1;++i,--j)
    		if(s[i][j]!=name[i-a])
    			return false;
    	return true;
    }
    bool searchrighdown(int a,int b,char name[])
    {
    	int i=a,j=b;
    	if((i+len-1>=n)||(j+len-1>=n))
    		return false;
    	for(;i<=a+len-1;++i,++j)
    		if(s[i][j]!=name[i-a])
    			return false;
    	return true;
    }
    pair<int,int> search(char name[])
    {
    	int i=0,j=0;
    	for(i=0;i<m;++i)
    	{
    		for(j=0;j<n;++j)
    		{
    			if(searchleft(i,j,name)||searchright(i,j,name)||searchup(i,j,name)||searchdown(i,j,name)||
    				searchleftup(i,j,name)||searchrightup(i,j,name)||searchleftdown(i,j,name)||searchrighdown(i,j,name))
    				goto loop;
    		}
    	}
    loop:
    	return make_pair(i,j);
    }
    int main()
    {
    	char name[100];
    	int cas;
    	while(scanf("%d",&cas)!=EOF)
    	{
    		while(cas--)
    		{
    			scanf("%d%d",&m,&n);
    			int i,j;
    			for(i=0;i<m;++i)
    			{
    				scanf("%s",s[i]);
    				for(j=0;s[i][j];++j)
    					if(s[i][j]>='A'&&s[i][j]<='Z')
    						s[i][j]=s[i][j]-'A'+'a';
    			}
    			int num;
    			scanf("%d",&num);
    			while(num--)
    			{
    				scanf("%s",name);
    				for(i=0;name[i];++i)
    					if(name[i]>='A'&&name[i]<='Z')
    						name[i]=name[i]-'A'+'a';
    				len=strlen(name);
    				pair<int,int> p=search(name);
    				printf("%d %d
    ",p.first+1,p.second+1);
    			}
    			if(cas)
    				printf("
    ");
    		}
    	}
    	return 0;
    }


  • 相关阅读:
    Flask 开启跨域
    pandas to dict
    mongodb 聚合查询
    flask 获取请求参数
    CSS dppx详解
    用CSS做出漂亮的字体动画
    VMware虚拟主机安装完成后连接不上网络
    wokerman中自定义协议的使用和测试
    使用workerman写一个小的聊天室
    telnet不能使用怎么办?
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3190141.html
Copyright © 2020-2023  润新知