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

ACM PKU 1458 Runtime Error java语言 求高手帮帮忙!

Posted by yfkscugs at 2010-09-10 15:04:06
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(System.in);
		String string = scanner.nextLine();
		int index = 0;
		while (string.charAt(index) == ' ')
			index++;

		while (string.charAt(index) != ' ')
			index++;

		char[] a = string.substring(0, index).toCharArray();

		while (string.charAt(index) == ' ')
			index++;

		char[] b = string.substring(index).toCharArray();
		System.out.println(f2(a, b));
	}

	public static int f2(char[] a, char[] b) {
		int r = a.length;
		int c = b.length;
		int i, j;
		int[][] record = new int[r][c];
		for (i = 0; i < r; i++)
			if (a[i] == b[0])
				record[i][0] = 1;

		for (i = 0; i < c; i++)
			if (b[i] == a[0])
				record[0][i] = 1;

		for (i = 1; i < r; i++)
			for (j = 1; j < c; j++)
				if (a[i] == b[j])
					record[i][j] = record[i - 1][j - 1] + 1;
				else {
					int c1 = record[i - 1][j];
					int c2 = record[i][j - 1];
					record[i][j] = c1 > c2 ? c1 : c2;
				}

		return record[r - 1][c - 1];
	}
}

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