玛雅日历转化(Maya calendar,POJ1008, UVA300)
瑪雅日歷轉化(POJ1008, UVA300)
這個是我個人的總結,方便與解題
Haab歷法
Haab歷法,一年有365天。Haab歷法每年有19個月,在前18個月, 每月有20天,月份的名字分別是pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu。 這些月份中的日期用0到19表示;Haab歷的最后一個月叫做uayet, 它只有5天,用0到4表示。Tzolkin歷法
一年被分成13個不同的時期,每個 時期有20天,每一天用一個數字和一個單詞相組合的形式來表示。 使用的數字是1~13,使用的單詞共有20個,它們分別是:imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau。 注意:年中的每一天都有著 明確唯一的描述,比如,在一年的開始,日期如下描述: 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的月份用數字表示,天數用數字表示1-13,并且使用20單詞
思路
以下是原題(建議打開谷歌翻譯)
Maya Calendar , POJ1008, UVA300
Description
During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day long year, called Haab, which had 19 months. Each of the first 18 months was 20 days long, and the names of the months were pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu. Instead of having names, the days of the months were denoted by numbers starting from 0 to 19. The last month of Haab was called uayet and had 5 days denoted by numbers 0, 1, 2, 3, 4. The Maya believed that this month was unlucky, the court of justice was not in session, the trade stopped, people did not even sweep the floor.
For religious purposes, the Maya used another calendar in which the year was called Tzolkin (holly year). The year was divided into thirteen periods, each 20 days long. Each day was denoted by a pair consisting of a number and the name of the day. They used 20 names: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers; both in cycles.
Notice that each day has an unambiguous description. For example, at the beginning of the year the days were described as follows:
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, and again in the next period 8 imix, 9 ik, 10 akbal . . .
Years (both Haab and Tzolkin) were denoted by numbers 0, 1, : : : , where the number 0 was the beginning of the world. Thus, the first day was:
Haab: 0. pop 0
Tzolkin: 1 imix 0
Help professor M. A. Ya and write a program for him to convert the dates from the Haab calendar to the Tzolkin calendar.
Input
The date in Haab is given in the following format:
NumberOfTheDay. Month Year
The first line of the input file contains the number of the input dates in the file. The next n lines contain n dates in the Haab calendar format, each in separate line. The year is smaller then 5000.
Output
The date in Tzolkin should be in the following format:
Number NameOfTheDay Year
The first line of the output file contains the number of the output dates. In the next n lines, there are dates in the Tzolkin calendar format, in the order corresponding to the input dates.
Sample Input 1
5 10. zac 0 0. pop 0 10. zac 1995 19. muan 2021 13. koyab 2002Sample Output 1
5 3 chuen 0 1 imix 0 9 cimi 2801 7 chicchan 2838 9 kan 2811源代碼
#include <iostream> #include <stdio.h> using namespace std; // 總結 // haab的月份用特定的字母表示,天數用數字表示 // Tzolkin的月份用數字表示,天數用數字表示1-13,并且使用20單詞 // 我暈為什么不用1-20來表示,我服 /* 定義Haab的19個月 因為c語言是沒有string類型,所以想用scanf會出錯想用scanf的話,可以將string類改成 char具體的操作為 char Haab[19][10]*/ string Haab[19] = {"pop", "no", "zip", "zotz","tzec", "xul", "yoxkin", "mol", "chen", "yax","zac", "ceh", "mac", "kankin", "muan", "pax","koyab", "cumhu", "uayet"}; /* 定義Tzolkin的20天*/ string Tzolkin[20] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi","manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem","cib", "caban", "eznab", "canac", "ahau"}; // 日期表示的信息 struct Data {int Date;//string類型的monthstring Month;int Year; }; //日期轉換函數 void convert(Data &x); int main() {int i, n;char ch; //儲存.字符//輸入的第一行表示要轉化的日期數量n// scanf("%d", &n);cin>>n;//創建一個一維數組Data *p = new Data[n];for (int i = 0; i < n; i++){//為什么scanf和cin輸入方式不同就有著這么大的差別// scanf("%d. %s %d", &p[i].Date, &p[i].Month, &p[i].Year);cin>>p[i].Date>>ch>>p[i].Month>>p[i].Year;}printf("%d\n", n);for (int i = 0; i < n; i++){convert(p[i]);}system("pause");return 0; } void convert(Data &x) {//代表從世界開始記起的天數long current;//代表月份int month;//尋找haab月份代表是那個數字for (month = 0; month < 20; month++) //當前月份是Haab歷的哪個月{if (x.Month == Haab[month])break;}current = x.Year * 365 + month * 20 + x.Date + 1;int num, year = 0; /* num為輸出中的數字,year為輸出中的年份 */string word; /* 月份名稱 *///求月份的時候會遇到兩種情況/* 余數為0則為一個整月num=13余數不為零則月數等于余數*/if (current % 13 == 0){num = 13; //}else{num = current % 13;}//求年份/* 減260天即可 */while ((current - 260) > 0){++year;current -= 260;}//開始判斷天數//如果天數=0說明是上一年的最后一天if (current == 0){word = "ahau";}else{//除以20繼續判斷current = current % 20;//和之前判斷天數一樣if (current == 0){word = "ahau"; /* 表示前一個月的最后一天 */}else{word = Tzolkin[current - 1];}// printf("%d %s %d\n",num,word,year);cout<<num<<" "<<word<<" "<<year<<endl;} }總結
以上是生活随笔為你收集整理的玛雅日历转化(Maya calendar,POJ1008, UVA300)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue使用高德地图web端JSAPI 路
- 下一篇: maya python插件_使用Pyth