Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请高人指点一下!总是WA!

Posted by 589742 at 2006-08-26 11:51:46 on Problem 2386
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator