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写了一段代码,不知道哪里错了,显示wrong answer.求大神指教。

Posted by AllMyBloods at 2012-10-15 15:57:46 on Problem 1008
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {	
		Scanner cin = new Scanner(System.in);
		
		while(cin.hasNext()){
	    List<Integer> list = new ArrayList<Integer>();
		int	n = cin.nextInt();
			for (int i = 0; i < n; i++) {
				int totalDays = 0;
				String day = cin.next();
				String month = cin.next();
				day = day.substring(0, day.lastIndexOf('.'));
				int year = cin.nextInt();
				int monthnum = 0;
				int daynum = 0;
				monthnum = monthChange(month);
				daynum = Integer.parseInt(day);
	            totalDays = year * 365 + monthnum * 20 + daynum + 1;
				list.add(totalDays);
			}
		
        System.out.println(n);
		Iterator it = list.iterator();
		while (it.hasNext()) {
			int res=(Integer) it.next();
			int TzolkinYear=res/260;
			int TzolkinMonth=(res)%13;  if(TzolkinMonth==0){TzolkinMonth=13;}
			int TzolkinDays=(res)%20;  if(TzolkinDays==0){TzolkinDays=20;}
			String  TzolkinDayString=dayChange(TzolkinDays-1);
			System.out.println(TzolkinMonth+" "+TzolkinDayString+" "+TzolkinYear);
		}
		}
	}

	public static int monthChange(String word) {
		String wholeMonth = "pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu ,uayet";
		String[] monthArray = wholeMonth.split(",");
		int num = 0;
		for (int x = 0; x < 19; x++) {
			if (monthArray[x].contains(word)) {
				num = x;
			}
		}
		return num;
	}
	
	public static String dayChange(int day)
	{
		String wholeDays="imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau";
		String []days=wholeDays.split(",");
		String res="";
		for(int i=0;i<20;i++)
		{ if(i==day) res=days[i];}
		
		return res;
		
	}
}


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