CodeForces 710A King Moves(水题-越界问题)

时间:2023-03-08 18:08:47

题目链接:http://codeforces.com/problemset/problem/710/A

题目大意:在一个棋盘中给出一个位置,判断该位置周围8个点还有几个点可以摆放棋子。

CodeForces 710A King Moves(水题-越界问题)

AC代码解释解法:

 #include<bits/stdc++.h>
using namespace std;
int main()
{
char c;
int x,y;
while(~scanf("%c%d",&c,&x))
{
getchar();
y=c-'a'+;
if((x==&&y==)||(x==&&y==)||(x==&&y==)||(x==&&y==))
{
printf("3\n");
}
else if((x==)||(x==)||(y==)||(y==))
{
printf("5\n");
}
else
printf("8\n");
}
return ;
}