样例输入:
1
6
99 99 99 99 99 99
99 99 99 50 99 99
99 99 49 49 50 51
99 50 20 25 52 99
40 50 99 99 99 99
99 99 99 99 99 99
样例输出:
Case#1:9 8
package com.hbut.util;
import java.util.Scanner;
public class TestArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int index=0;
int arrSize[] = new int[2];
//控制输入的数据个数
while (index<=1) {
arrSize[index]=in.nextInt();
index++;
}
int M=arrSize[0];
int N=arrSize[1];
int arr[][]= new int[N][N];
int total=0;
int area=0;
for(int n=0;n<N;n++){
for(int y=0;y<N;y++){
total++;
//控制输入的总的个数
if(total<=N*N){
arr[n][y]=in.nextInt();
if(arr[n][y]<=50&&arr[n][y]>=0){
area++;
}
continue;
}
}
}
// int num=0;
// for(int n=0;n<N;n++){
// for(int y=0;y<N;y++){
// num++;
// if(num%N==0)
// {
// System.out.print(arr[n][y]+"\n");
// }
// else {
// System.out.print(arr[n][y]+" ");
//
// }
//
// }
// }
int lon=0;
//判断边界个数
for(int x=0;x<N;x++){
for(int y=0;y<N;y++){
//定义一个数的上下左右数
if(arr[x][y]<=50){
int a=0;
int b=0;
int c=0;
int d=0;
if(x-1>=0){
a=arr[x-1][y];//上面的点
}
if(x+1<N){ //下面的点
b=arr[x+1][y];
}
if(y-1>=0){ //左边的点
c=arr[x][y-1];
}
if (y+1<N){ //右边的点
d=arr[x][y+1];
}
if(a>50||b>50||c>50||d>50){
lon++;
}
}
}
}
System.out.println("Case#"+M+":"+area+" "+lon);
}
}