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

大家帮忙看看我的JAVA程序,还能有什么样的特殊数据过不去呢

Posted by gostopsb at 2006-11-11 14:48:54 on Problem 1006
import java.util.*;

public class Biorhythms
{
	public static int nextPeak(int p, int e, int in)
	{
		
        
		if(p<0||e<0||in<0)
		{
			System.exit(0);
		}
		
		for (int i = in; true; i = i + 33)
		{

			if ((i - p) % 23 == 0 && (i - e) % 28 == 0 && (i - in) % 33 == 0)
			{
				if (p == 0 && e == 0 && in == 0)
				{
					return 21252;
				} else
				{
						
						return i;
					
				}
			}
		}
	
	}

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);

		int p = sc.nextInt();
		int e = sc.nextInt();
		int in = sc.nextInt();
		int day = sc.nextInt();
		
		if(day>365)
		{
			System.exit(0);
		}

		int count = 1;
		ArrayList result = new ArrayList(30);
		while (!(p == -1 && e == -1 && in == -1 && day == -1))
		{

			// result[count] = nextPeak(p, e, in) - day;
			int temp=nextPeak(p,e,in)-day;
			if(temp>21252)
				temp=temp-21252;
			
			result.add(temp);

			count++;

			p = sc.nextInt();
			e = sc.nextInt();
			in = sc.nextInt();
			day = sc.nextInt();
		}

		for (int i = 1; i < count; i++)
		{
			System.out.println("Case " + i
					+ ": the next triple peak occurs in " + result.get(i - 1)
					+ " days.");
		}
	}
}

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