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 Main { int[] num; int n; int k; String div = "Not divisible"; public Main(int[] x, int y, int z) { num = x; n = y; k = z; } public void p(int index,int value) { for(int i=0;i<2;i++) { if(i==0&&div.equals("Not divisible")) { if(index >= n-1) { if(value%k==0) { div ="Divisible"; //System.out.println(value); } return ; } else p(index+1,value + num[index+1]); } if(i==1&&div.equals("Not divisible")) { if(index >= n-1) { if(value%k==0) { div ="Divisible"; // System.out.println(value); } return ; } else p(index+1,value - num[index+1]); } } } public static void main(String arg[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); StringTokenizer st = new StringTokenizer(s); int n = Integer.parseInt(st.nextToken()); if(n<=0) { System.out.println("Not divisible"); return; } int k =0; if(k==0) { System.out.println("Not divisible"); return; } k = Integer.parseInt(st.nextToken()); s= br.readLine(); st = new StringTokenizer(s); int[] num = new int[n]; int i = 0; while(st.hasMoreTokens()) { num[i] = Integer.parseInt(st.nextToken()); i++; } //System.out.println(num[n-1]); Main m = new Main(num, n ,k); m.p(0, num[0]); System.out.println(m.div); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator