题目出处
题意:玛雅人有两种历法,题目要求从键盘输入一中历法,通过程序转换成另一种历法
解法:模拟
思路:先通过输入求出haab历法的总天数,再对应holly历法进行转换就行了
代码(C++):
/* 308K 0MS */ #include <iostream> #include <map> #include <string> using namespace std; typedef struct { float da; string mo; int ye; } Data; Data d; map<string, int> haab; map<int, string> holly; void fun(Data *d); void inithaab(); void initholly(); int main() { int n; int flag=1; inithaab(); initholly(); cin >> n; for (int i = 0; i < n; i++) { if (flag == 1) { cout << n << endl; flag = 0; } cin >> d.da >> d.mo >> d.ye ; fun(&d); } return 0; } void fun(Data *d) { int ye, da; string mo; long ha_all_day; ha_all_day = d->ye * 365 + haab[d->mo] + (int)d->da; da = ha_all_day % 260 % 13 + 1; mo = holly[ha_all_day % 260 % 20]; ye = ha_all_day / 260; cout << da << " " << mo << " " << ye << endl; } void inithaab() { //haab : pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, //pax, koyab, cumhu,uayet haab.insert(make_pair("pop", 0)); haab.insert(make_pair("no", 20)); haab.insert(make_pair("zip", 40)); haab.insert(make_pair("zotz", 60)); haab.insert(make_pair("tzec", 80)); haab.insert(make_pair("xul", 100)); haab.insert(make_pair("yoxkin", 120)); haab.insert(make_pair("mol", 140)); haab.insert(make_pair("chen", 160)); haab.insert(make_pair("yax", 180)); haab.insert(make_pair("zac", 200)); haab.insert(make_pair("ceh", 220)); haab.insert(make_pair("mac", 240)); haab.insert(make_pair("kankin", 260)); haab.insert(make_pair("muan", 280)); haab.insert(make_pair("pax", 300)); haab.insert(make_pair("koyab", 320)); haab.insert(make_pair("cumhu", 340)); haab.insert(make_pair("uayet", 360)); } void initholly() { //holly : imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, //mem, cib, caban, eznab, canac, ahau holly.insert(make_pair(0, "imix")); holly.insert(make_pair(1, "ik")); holly.insert(make_pair(2, "akbal")); holly.insert(make_pair(3, "kan")); holly.insert(make_pair(4, "chicchan")); holly.insert(make_pair(5, "cimi")); holly.insert(make_pair(6, "manik")); holly.insert(make_pair(7, "lamat")); holly.insert(make_pair(8, "muluk")); holly.insert(make_pair(9, "ok")); holly.insert(make_pair(10, "chuen")); holly.insert(make_pair(11, "eb")); holly.insert(make_pair(12, "ben")); holly.insert(make_pair(13, "ix")); holly.insert(make_pair(14, "mem")); holly.insert(make_pair(15, "cib")); holly.insert(make_pair(16, "caban")); holly.insert(make_pair(17, "eznab")); holly.insert(make_pair(18, "canac")); holly.insert(make_pair(19, "ahau")); }
/* 168K 16MS */ #include <stdio.h> #include <string.h> int main() { //haab : pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu,uayet //holly : imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau char haab[20][10] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"}; char holly[20][10] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"}; int ye, da; char mo[10]; int all_day; int n; int i; scanf("%d", &n); printf("%d\n", n); while (n-- && scanf("%d. %s %d", &da, mo, &ye)) { for (i = 0; i < 20; i++) { if (!strcmp(haab[i], mo)) break; } all_day = ye * 365 + 20 * i + da; printf("%d %s %d\n", all_day % 260 % 13 + 1, holly[all_day % 260 % 20], all_day / 260 ); } return 0; }