解题思路:
首先根据案例推算棋盘大小-------> 推算出来是8*8
然后按照题意一次判断上左,上右,下左,下右,左上,左下,右上,右下是否在棋盘内,如果在则count++;
注意事项:
参考代码:
static void f1() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] test = new int[n][2]; //处理输入将坐标放置在一个数组里 for (int i = 0; i < test.length; i++) { char[] c = sc.next().toCharArray(); test[i][0] = c[0]-'a'; test[i][1] = c[1] -'1'; } for (int i = 0; i < n; i++) { int count = 0; int x = test[i][0]; int y = test[i][1]; if(x-2>=0&&y-1>=0) //上左 count++; if(x-2>=0&&y+1<8) //上右 count++; if(x+2=0) //下左 count++; if(x+2<8&&y+1=0&&x+1=0&&x-1>=0) //左下 count++; if(y+2<8&&x+1<8) //右上 count++; if(y+2=0) //右下 count++; System.out.println(count); } }
0.0分
0 人评分
【明明的随机数】 (C++代码)(C++库中有qsort函数直接快排,不用码排序代码hhh)浏览:974 |
C语言程序设计教程(第三版)课后习题6.9 (C++代码)论pow函数的应用浏览:1025 |
矩形面积交 (C语言代码)浏览:1513 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:509 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:518 |
C语言训练-求PI* (C语言代码)浏览:613 |
淘淘的名单 (C语言代码)浏览:1100 |
本人酷爱递归实现很多问题,这里也是浏览:553 |
WU-输出正反三角形 (C++代码)浏览:1018 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:556 |