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 gsb7814 at 2005-10-06 17:23:14 on Problem 1008
此程序是用Java编写的。
我用题目给的输入数据得到下面的结果:前两行结果是正确的,
第三行是不正确的,这行的NameOfTheDay怎么推后了一个,本应该是9 cimi 2801
请高手指点。谢谢!^_^
3
3 chuen 0
1 imix 0
9 manik 2801

以下是源码:

import java.util.*;
import java.io.*;

public class MayaCalender {
  public static void main(String[] args) {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    Hashtable ht;
    int Tmon,Tday,Tyear;
    int days;
    StringTokenizer st;
    String[]TdayName={"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
    int []Tnumber={1,2,3,4,5,6,7,8,9,10,11,12,13};
    int  mon[],day[],year[];
    String monthT;
    try {
      int n = Integer.parseInt(br.readLine());
      mon=new int[n];
      day=new int[n];
      year=new int[n];
      ht=new Hashtable(n);
      String monStr[]=new String[n];
      String monName[]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin","mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu"};
      //pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu
      for(int j=0;j<monName.length;j++){
        ht.put(monName[j],new Integer(j));
      }
       System.out.println(n);
      for(int i=0;i<n;i++){
        st=new StringTokenizer(br.readLine());
        String tmp=st.nextToken();
        int  len=tmp.length();
        day[i]=Integer.parseInt(tmp.substring(0,len-1));
        //day[i]=Integer.parseInt(tmp);
        monStr[i]=st.nextToken();

        year[i]=Integer.parseInt(st.nextToken());
        mon[i]=((Integer)ht.get(monStr[i])).intValue();
        days=year[i]*365+(mon[i])*20+day[i];
        Tyear=days/260;
       Tmon=(int)(days%260)/20;
        monthT=TdayName[Tmon];
        Tday=(int)(days%260%13+1);
        System.out.println(Tday+" "+monthT+" "+Tyear);
        }
      }
    catch (IOException ex) {
      ex.printStackTrace();
    }
    catch (NumberFormatException ex) {
      ex.printStackTrace();
    }
  }
}

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