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 |
哪位高手看一看 我的代码为什么runtime error啊import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String strNum = bf.readLine(); int n = Integer.parseInt(strNum); int triangle[][] = new int[100][100]; for (int i = 0; i < n; i++) { for (int j = 0; j < i + 1; j++) { String strTriEle = bf.readLine(); triangle[i][j] = Integer.parseInt(strTriEle); } } // 判断各次的值 int temp = 0; for (int i = 1; i < n; i++) { for (int j = 0; j < i + 1; j++) { if (j >= 1) { triangle[i][j] = triangle[i][j] + Math.max(triangle[i-1][j-1],triangle[i-1][j]); temp = triangle[i][j]; }else { temp = triangle[i][j] = triangle[i-1][j] + triangle[i][j]; } } } int maxVal = 0; for (int i = 1; i < n; i++) { if( triangle[n-1][i] > maxVal){ maxVal = triangle[n-1][i]; } } System.out.println(maxVal); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator