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! Can anyone tell me why?

Posted by SE06XMX at 2007-07-03 17:04:49 on Problem 2575
My codes are here:


import java.io.*;
import java.util.*;
import java.lang.Math;
public class Main
{
            public static void main(String args[]) throws Exception
            {
                    Vector<sets> v=new Vector<sets>();
                    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   
                     String line = "";
                    while (((line = br.readLine()) != null)){   
                       
    
                      if(!line.trim().equals(""))
                       v.add(new sets(line));
                      else   break;   
                    }
  
                    for(int i=0;i<v.size();i++)
                    {
                    	System.out.println(v.elementAt(i).isJolly());
                    }
            }
}

class sets
{
	private String nums;
	public sets(String s)
	{
		nums=s;
	}
	public String isJolly()
	{
		if(jolly())
		return "Jolly";
		else
		return "Not jolly";

	}
	private boolean jolly()
	{
		
		
		StringTokenizer st = new StringTokenizer(nums);
        int n = Integer.parseInt(st.nextToken());
        int set[]=new int[n];
		n=0;
		while(true)
		{
			set[n]=Integer.parseInt(st.nextToken());
			n++;
			if(n==set.length)
			break;
		}
		
		for(int i=0;i<set.length-1;i++)
		{
			set[i]=Math.abs(set[i]-set[i+1]);

		
		}
		boolean f=false;
		for(int j=set.length-1;j>=1;j--)
		{
			for(int k=0;k<set.length-1;k++)
			{
				if(set[k]==j)
				{
					f=true;
					break;
				}
				
			}
			if(f==false)
			return false;
			else if(j==1)
			return true;
			f=false;
		}
		
		return true;
		
	}	

}

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