实际编程题----CT扫描




样例输入:

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);




}


}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值