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

求助: java 总是re,为什么啊?

Posted by Maybesky at 2007-05-04 21:32:58 on Problem 1998
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[][] dir = new int[4][2];
		dir[0][0] = 0;
		dir[0][1] = 1;
		dir[1][0] = 0;
		dir[1][1] = -1;
		dir[2][0] = 1;
		dir[2][1] = 0;
		dir[3][0] = -1;
		dir[3][1] = 0;
		//= { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };
		String[] out = new String[4];//{  "doleva", "doprava", "nahoru" , "dolu" };
		out[0] = "doleva";
		out[1] = "doprava";
		out[2] = "nahoru" ;
		out[3] = "dolu";
		Scanner cin = new Scanner(System.in);
		int time = cin.nextInt();
		for (int t = 1; t <= time; t++) {
			System.out.println("Skladacka cislo " + t + ":");
			int r = cin.nextInt();
			int s = cin.nextInt();
			int fx = 0;
			int fy = 0;
			int[][] chess = new int[r][s];
			for (int i = 0; i < r; i++)
				for (int j = 0; j < s; j++) {
					chess[i][j] = cin.nextInt();
					if (chess[i][j] == 0) {
						fx = i;
						fy = j;
					}
				}
			int m,tx,ty;
			while((m = cin.nextInt()) > 0){
				for (int d = 0; d < 4 ; d++){
					tx = fx + dir[d][0];
					if (tx < 0||tx>=r) 
						continue;
					ty = fy + dir[d][1];
					if (ty < 0 || ty >= s)
						continue;
					if (chess[tx][ty] == m){
						System.out.println("Kamen " + m + " presunut " + out[d] + ".");
						chess[fy][fx] = m;
						chess[tx][ty] = 0;
						fx = tx;
						fy = ty;
						break;
					}
					if (d == 3)
						System.out.println("Neplatny tah kamenem " + m + ".");
				}
			}
			
			for (int x = 0; x < r; x++) {
				for (int y = 0; y < s; y++)
					System.out.print(chess[x][y] + " ");
				System.out.println();
			}
			System.out.println();
		}
	}
}

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