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

Wrong Answer, I get Wrong answer, please help

Posted by dorwardv at 2008-06-15 19:16:15 on Problem 2575 and last updated at 2008-06-15 20:25:38
need 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:
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