解题思路:
注意事项:
#include<stdio.h> void Fun(char x, int y, int* num); int ju[11][11] = { 0 }; int main() { int f = 0; int i = 0; int n = 0; int j = 0; int result[15] = { 0 }; for (i = 1; i <= 8; i++)//横竖都是8 { for (j = 1; j <= 8; j++) { ju[i][j] = 1;// } } f = scanf("%d", &n); getchar(); for (i = 1; i <= n; i++) { int num = 0; char x = '\0'; int y = 0; //x = getchar(); f = scanf("%c%d", &x,&y); getchar(); Fun(x, y, &num); result[i] = num; } for(i = 1;i<=n;i++) { printf("%d\n", result[i]); } } void Fun(char x_char, int y, int* num) { int x = 0; x_char = x_char - 'a' + 1; x = x_char;//求出x和y //右2,上下1 if (ju[x + 2][y + 1] == 1) { (*num)++; } if (ju[x + 2][y - 1] == 1) { (*num)++; } //左2上下1 if (ju[x - 2][y + 1] == 1) { (*num)++; } if (ju[x - 2][y - 1] == 1) { (*num)++; } //右1上下2 if (ju[x + 1][y + 2] == 1) { (*num)++; } if (ju[x + 1][y - 2] == 1) { (*num)++; } //左1上下2 if (ju[x - 1][y + 2] == 1) { (*num)++; } if (ju[x - 1][y - 2] == 1) { (*num)++; } return; }
0.0分
3 人评分