Scanner


私信TA

用户名:1505256190

访问量:2312

签 名:

等  级
排  名 2973
经  验 1995
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校 中北大学
专  业

  自我简介:

解题思路:
    首先根据案例推算棋盘大小-------> 推算出来是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 人评分

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

编程语言转换

万能编程问答

代码解释器

  评论区