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 |
Wrong Answer, I get Wrong answer, please helpneed more inputs to test my code. please help [code] import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main { public static boolean isJolly(ArrayList<Integer> list){ System.out.println(list); boolean retVal = list.size() > 1; if (list.size() > 1){ ArrayList<Integer> result = new ArrayList<Integer>(); for(int index=0;index<list.size()-1;index++){ result.add(Math.abs(list.get(index)-list.get(index+1))); } Collections.sort(result); System.out.println(result); for (int i=0;i<result.size();i++){ if (result.get(i)!=i+1){ retVal = false; break; } } } return (list.size() == 1) || retVal; } public static void main (String args[]){ Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { int num = sc.nextInt(); ArrayList<Integer> list = new ArrayList<Integer>(num); for (int i = 0;i<num;i++){ list.add(sc.nextInt()); } if (isJolly(list)) System.out.println("Jolly"); else System.out.println("Not jolly"); } } } [/code] Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator