玛雅日历转化(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单词

思路

  1. 求出haab日历中的天数,因为两个日历惟一的共同点,就是从世界开始的那一天算起的
  2. 按照这个思路走,先求年%260(求余)
  3. 再求月
  4. 求天数,并且求出数字代表的特定的单词

以下是原题(建议打开谷歌翻译)

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 2002

Sample Output 1

5
3 chuen 0
1 imix 0
9 cimi 2801
7 chicchan 2838
9 kan 2811

源代码

#include 
#include 
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类型的month
    string 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<

你可能感兴趣的:(算法,c++)