解题思路:
分情况讨论
注意事项:
参考代码:
#include <stdio.h>
int main(void)
{
int i, n, x, y, count;
char c;
scanf("%d", &n);
getchar();
for (i = 1;i <= n;i++)
{
count = 0;
c = getchar();
scanf("%d", &y);
getchar();
switch (c)
{
case 'a':x = 1;break;
case 'b':x = 2;break;
case 'c':x = 3;break;
case 'd':x = 4;break;
case 'e':x = 5;break;
case 'f':x = 6;break;
case 'g':x = 7;break;
case 'h':x = 8;break;
}
//左上
if (x >= 3)
{
if (y == 1)
count = count;
else if (y == 2)
count++;
else
count = count + 2;
}
else
{
if (x == 2)
{
if (y >= 3)
count++;
else
count = count;
}
else
count = count;
}
//右上
if (x <= 6)
{
if (y == 1)
count = count;
else if (y == 2)
count++;
else
count = count + 2;
}
else
{
if (x == 7)
{
if (y >= 3)
count++;
else
count = count;
}
else
count = count;
}
//左下
if (x >= 3)
{
if (y == 8)
count = count;
else if (y == 7)
count++;
else
count = count + 2;
}
else
{
if (x == 2)
{
if (y <= 6)
count++;
else
count = count;
}
else
count = count;
}
//右下
if (x <= 6)
{
if (y == 8)
count = count;
else if (y == 7)
count++;
else
count = count + 2;
}
else
{
if (x == 7)
{
if (y <= 6)
count++;
else
count = count;
}
else
count = count;
}
printf("%d\n", count);
}
return 0;
}
0.0分
1 人评分
钟神赛车 (C++代码)浏览:905 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:553 |
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:481 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:287 |
C语言训练-排序问题<1> (C语言代码)浏览:636 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:467 |
众数问题 (C语言代码)浏览:911 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:760 |
sizeof的大作用 (C语言代码)浏览:1591 |
小九九 (C语言描述,不看要求真坑爹)浏览:1006 |