Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请高人指点一下!总是WA!import java.io.*; import java.util.*; public class LakeCounting { private int row = 1; private int column = 1; private char[][] array; private int number = 0; public void init() { try { Scanner scan = new Scanner(System.in); row = scan.nextInt(); column = scan.nextInt(); array = new char[row][column]; for(int i = 0;i < row;i ++) { String temp = scan.next(); for(int j = 0;j < column;j ++) { array[i][j] = temp.charAt(j); } } } catch(Exception e) {} } public int getNumber(int i,int j) { int flag = 0; if(array[i][j] == 'W') { array[i][j] = '.'; flag = 1; if((i+1) <= (row-1)) { if((j-1) >= 0) getNumber(i+1,j-1); getNumber(i+1,j); if((j+1) <= (column-1)) getNumber(i+1,j+1); } if((j+1) <= (column-1)) getNumber(i,j+1); } return flag; } public void run() { for(int i = 0;i < row;i ++) { for(int j = 0;j < column;j ++) { int m = getNumber(i,j); number = number + m; } } System.out.println(number); } public static void main(String[] args) { LakeCounting lc = new LakeCounting(); lc.init(); lc.run(); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator