妖三欺


私信TA

用户名:s237834893

访问量:5383

签 名:

代码千万行,注释第一行

等  级
排  名 2440
经  验 2211
参赛次数 0
文章发表 17
年  龄 0
在职情况 学生
学  校 哈尔滨工程大学
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>
int fun(int x,int y)
{
    int sum=0;
    x--;y--;
    for(int i=-2;i<=2;i=i+4)
    {
        int tx;
        tx=x+i;
        for(int j=-1;j<=1;j=j+2)
        {
            int ty;
            ty=y+j;
            if((tx<=7)&&(tx>=0)&&(ty<=7)&&(ty>=0))sum++;
        }
    }
    for(int i=-2;i<=2;i=i+4)
    {
        int ty;
        ty=y+i;
        for(int j=-1;j<=1;j=j+2)
        {
            int tx;
            tx=x+j;
            if((tx<=7)&&(tx>=0)&&(ty<=7)&&(ty>=0))sum++;
        }
    }
    return sum;
}
int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    for(int m=0;m<n;m++)
    {
        char t;
        int x,y=0;
        scanf("%c %d",&t,&y);
        if(t=='a')x=1;
        else if(t=='b')x=2;
        else if(t=='c')x=3;
        else if(t=='d')x=4;
        else if(t=='e')x=5;
        else if(t=='f')x=6;
        else if(t=='g')x=7;
        else if(t=='h')x=8;
        printf("%d \n",fun(x,y));
        getchar();
    }
    return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区