首页 > 代码库 > POJ1008
POJ1008
Description:
玛雅使用两种日历,第一种称为Haab,一年为365天,一年分为19个月,前18个月每个月都是20天,第19个月为5天,每一个月都有一个名字,分别为pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu和uayet,每个月份中的天数用0到19表示。最后一个月份中的天数用0到4表示。玛雅使用的第二个日历称为Tzolkin,在这个日历中,一年为260天,一年分为13段,每段20天(260=13*20),每一天用一个数字和一个名字表示,总共20个名字: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau,数字为1到13,数字和名字都顺序循环,例如,第一年开始的几天为:1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, 然后进入下一段 8 imix, 9 ik, 10 akbal。。。
现在的任务是要将一个Haab日历格式的日期转换为Tzolkin日历格式的日期。年份从0开始,从日期开始点开始,第一天在两种日历中分别为:
Haab:0. pop 0
Tzolkin: 1 imix 0
输入:
输入的日期为Haab日历格式,第一行输入日期的个数,第二行开始输入日期。输入日期的格式为:
天数.月份 年份 例如: 10. zac 0,天数和年份都从0开始
输出:
输出的日期为Tzolkin日历格式。第一行输出日期的个数,第二行开始输出Tzolkin格式的日期,输出日期的格式为:
数字 天名字 年份 例如:3 chuen 0, 数字为1到13,年份从0开始
-----------------------------------------------------------------------------------我是华丽的分割线----------------------------------------------------------------------------------
思路:
//先把第一个日历转换成数字然后再转换成另一个日历
//des=365*年份+月份*20+数字日期
//HOLLY year的年份==data/260
//HOLLY year的月份==data%260/13+1
//HOLLY year的日期==data%260%20 对应的短语
注意一下输入的方式:
char zhongjian[50]={}; cin>>day>>zhongjian>>zhongjian>>year;
还有数组下标和字符串的对应:
char *Haab[] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"}; int searchStr(char *list[],int n,char *str){ for(int i=0;i<n;i++) { if(strcmp(list[i],str)==0) return i; } return -1;}
还有关于变量的命名方式,可以采用hd,hm,hy的方式,以免不知道如何命名。
源代码:
/*Haab, which had 19 months:(NumberOfTheDay. Month Year)Each of the first 18 months was 20 days longpop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu.uayet numbers 0, 1, 2, 3, 4*//* Tzolkin (holly year):thirteen periods, each 20 days long. (Number NameOfTheDay Year) a number and the name of the day: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers;*/#include <iostream>#include <string>using namespace std;char zhongjian[50]={};char *Haab[] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"}; char *Tzolkin[] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"}; //struct result //{ // char s[24]; // struct result *next; //};//因为不知道是多少个,只能用链表进行存储int searchStr(char *list[],int n,char *str){ for(int i=0;i<n;i++) { if(strcmp(list[i],str)==0) return i; } return -1;}//struct result* insert(char a[]){// struct result *head=NULL,*pf,*pb;// pb = (struct result *)malloc(sizeof(struct result));// *pb ->s = *a;// if(head==NULL) pf=head=pb;// else pf->next = pb;// pb ->next = NULL;// pf =pb;// return head;//}int main(){ int N=0; int year,month,day,data; //struct result *p,*first;//用于输出 cin>>N; cout<<N<<endl; //先把第一个日历转换成数字然后再转换成另一个日历 //des=365*年份+月份*20+数字日期 //HOLLY year的年份==data/260 //HOLLY year的月份==data%260/13+1 //HOLLY year的日期==data%260%20 对应的短语 for(int i=0;i<N;i++) { /*scanf("%d.%s %d",&day,zhongjian,&year);*/ cin>>day>>zhongjian>>zhongjian>>year; month = searchStr(Haab,19,zhongjian); data = 365*year+month*20+day; year = data/260; month =data%260%13+1; day = data%260%20; cout<<month<<" "<<Tzolkin[day]<<" "<<year<<endl; //保存转换结果 /*sprintf(zhongjian,"%d %s %d", day, Tzolkin[month], year); first=insert(zhongjian);*/ } /*printf("%d\n",N); p = first; while(p!=NULL) { printf("%s\n",p->s); p = p->next; }*/ return 0;}
POJ1008