UVA 10010 Where's Waldorf?

AC代码
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define clr(a,b); memset(a,b,sizeof(a));
char a[100][100];
char word[30][100];
int dir[8][2]={{1,0},{1,1},{1,-1},{0,1},{0,-1},{-1,1},{-1,-1},{-1,0}};
int flag;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int T;
    int m,n,k;
    while(scanf("%d",&T)!=EOF)
    {
    while(T--)
    {
        clr(a,0);
        clr(word,0);
        flag=0;
        scanf("\n");
        scanf("%d%d",&m,&n);getchar();
        for(int i=0;i<m;i++)
        gets(a[i]);
        for(int i=0;i<m;i++)
        for(int j=0;j<n;j++)
        {
            a[i][j]=toupper(a[i][j]);
        }
        scanf("%d",&k);
        getchar();
        for(int i=0;i<k;i++)
        gets(word[i]);
        for(int i=0;i<k;i++)
        for(int j=0;word[i][j]!='\0';j++)
        {
            word[i][j]=toupper(word[i][j]);
        }
        for(int c=0;c<k;c++)
        {
            for(int i=0;i<m;i++)
            {
            for(int j=0;j<n;j++)
            {
                if(a[i][j]==word[c][0])
                {
                    for(int b=0;b<8;b++)
                    {
                        int x=i;int y=j;int d=0;
                        while(a[x][y]==word[c][d])
                        {
                            d++;
                            x=x+dir[b][0];y=y+dir[b][1];
                            if(!isalpha(word[c][d]))
                            {printf("%d %d\n",i+1,j+1);flag=1;break;}
                        }
                        if(flag==1)
                        break;
                    }
                }
                if(flag==1)
                break;
            }
            if(flag==1)
                {
                    flag=0;
                    break;
                }
            }
        }
        if(T!=0)
        printf("\n");
    }
    }
    return 0;
}

这道水题竟然贡献了5次WA,有些小问题要注意吧,用了toupper转换小写字母为大写字母但是没有在头文件里加ctype.h,返回WA;

还有就是格式问题在UVA里返回WA,不返回PE,这和国内很多OJ不一样,每一组输入数据之间都有一个空行,第一组前面也有一个空行需要吸收掉,每一组输出数据都必须紧跟着输出一个空行,但是最后一组输出数据后面不输出空行,就是这样。

我拉了《算法竞赛入门经典》的作业题在HUST上,很方便的可以做作业了这样,欢迎大家来做。

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22953#overview

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22984#overview

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22985#overview

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22986#overview

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22987#overview

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22988#overview

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22989#overview

posted on 2013-05-06 20:06  Fray  阅读(188)  评论(0编辑  收藏  举报

导航