日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++程序练习-1008:Maya Calendar-玛雅日历

發布時間:2023/12/18 c/c++ 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++程序练习-1008:Maya Calendar-玛雅日历 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

描述
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.

輸入
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.

輸出
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.

樣例輸入
3
10. zac 0
0. pop 0
10. zac 1995
樣例輸出
3
3 chuen 0
1 imix 0
9 cimi 2801

分析問題:
Haab:19個月,前18個月每個月20天,最后一個月5天,一年365天。
Tzolkin:20個名字,20天一次循環,13個數字,13天一個循環,一年260天。
2種日歷一年的第一天固定。
思路:
根據Haab算出總天數,再按照Tzolkin的條件算出年月日。
注意事項:
第一行要輸出test cases的總數

//冰非寒(binfeihan@126.com) //252kB 10ms 1906 B G++ #include <iostream> #include <string> #include <cstdio> using namespace std; //global variables const string mHaab[] = { "pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"}; const string mTzolkin[]={ "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"}; const int N365 = 365; const int N260 = 260; const int N20 = 20; const int N19 = 19; const int N13 = 13; //class: Calendar typedef class Calendar{ public: int dayHaab; string monthHaab; int yearHaab; int dayTzolkin; string monthTzolkin; int yearTzolkin; int totalDays; void setTotalDays(); void setTzolkin(); void printTzolkin(); }Calendar; //calculate the total days void Calendar::setTotalDays(){ this->totalDays = this->yearHaab * N365; for(int i(0);i != N19;++ i){ if(this->monthHaab.compare(mHaab[i]) == 0){ this->totalDays += i * N20; break; } } this->totalDays += this->dayHaab + 1; } //set calendar of Tzolkin void Calendar::setTzolkin(){ this->setTotalDays(); this->yearTzolkin = (this->totalDays - 1)/ N260; this->totalDays %= N260; this->monthTzolkin = (this->totalDays % N20 == 0?mTzolkin[N19]:mTzolkin[this->totalDays % N20 - 1]); this->dayTzolkin = (this->totalDays % N13 == 0?N13:this->totalDays % N13); } //print calendar of Tzolkin void Calendar::printTzolkin(){ cout<<this->dayTzolkin<<' '<<this->monthTzolkin<<' '<<this->yearTzolkin<<endl; } //main function int main(){ int cases; Calendar cld; //store ',' char ch; cin>>cases; //print the number of test cases cout<<cases<<endl; while(cases --){ cin>>cld.dayHaab>>ch>>cld.monthHaab>>cld.yearHaab; cld.setTzolkin(); cld.printTzolkin(); } return 0; }

總結

以上是生活随笔為你收集整理的C++程序练习-1008:Maya Calendar-玛雅日历的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。