美文网首页
1008 Maya Calendar

1008 Maya Calendar

作者: 狂奔的皮皮花 | 来源:发表于2018-09-23 18:26 被阅读0次
#include <stdio.h>
#include <string.h>

int mon2int(char *str);

int main() {
    int n;
    char *dayNames[20] = {"imix", "ik", "akbal", "kan",
                          "chicchan", "cimi", "manik", "lamat",
                          "muluk", "ok", "chuen", "eb",
                          "ben", "ix", "mem", "cib",
                          "caban", "eznab", "canac", "ahau"};

    scanf("%d", &n);
    printf("%d\n", n);

    while (n > 0) {
        int NumberOfTheDay, Year;
        char Month[7];
        scanf("%d. %s %d", &NumberOfTheDay, Month, &Year);

        int days = Year * 365 + mon2int(Month) * 20 + NumberOfTheDay;

        int year, number, dayNumber;
        year = days / 260;
        int remainder = days % 260;
        number = remainder % 13 + 1;
        dayNumber = remainder % 20;

        printf("%d %s %d\n", number, dayNames[dayNumber], year);

        n --;
    }

    return 0;
}

int mon2int(char *str) {
    char *monthNames[19] = {"pop", "no", "zip",
                        "zotz", "tzec", "xul",
                        "yoxkin", "mol", "chen",
                        "yax", "zac", "ceh",
                        "mac", "kankin", "muan",
                        "pax", "koyab", "cumhu", "uayet"};
    for (int i = 0; i < 19; i ++) {
        if (!strcmp(monthNames[i], str)) {
            return i;
        }
    }

    return -1;
}

相关文章

网友评论

      本文标题:1008 Maya Calendar

      本文链接:https://www.haomeiwen.com/subject/tfjqoftx.html