//一道很不错的题目。忽略细节WA了3次 //要注意特殊情况 //如果是一年的最后一天,注意年份必须减1 //总结:在做关于取模运算时,注意考虑当结果为0时是否是你要的答案 #include<iostream> #include<map> #include<string> using namespace std; map<string,int> stoi; map<int,string> itos;//利用map关联容器实现月份与数字的对应以及数字与月份的对应 int n,dd,mm,yy; int DD,MM,YY,sumDay; char d[10]; string m; int main() { stoi["pop"] = 1;stoi["no"] = 2;stoi["zip"] = 3;stoi["zotz"] = 4;stoi["tzec"] = 5;stoi["xul"] = 6; stoi["yoxkin"] = 7;stoi["mol"] = 8;stoi["chen"] = 9;stoi["yax"] = 10;stoi["zac"] = 11;stoi["ceh"] = 12; stoi["mac"] = 13;stoi["kankin"] = 14;stoi["muan"] = 15;stoi["pax"] = 16;stoi["koyab"] = 17;stoi["cumhu"] = 18;stoi["uayet"] = 19; itos[1] = "imix";itos[2] = "ik";itos[3] = "akbal";itos[4] = "kan";itos[5] = "chicchan"; itos[6] = "cimi";itos[7] = "manik";itos[8] = "lamat";itos[9] = "muluk";itos[10] = "ok"; itos[11] = "chuen";itos[12] = "eb";itos[13] = "ben";itos[14] = "ix";itos[15] = "mem"; itos[16] = "cib";itos[17] = "caban";itos[18] = "eznab";itos[19] = "canac";itos[20] = "ahau"; cin >> n; cout << n << endl; while(n--) { cin >> d >> m >> yy; dd = atoi(d) + 1;//注意加1,用atoi即可实现简单的转化 mm = stoi[m]; sumDay = yy * 365 + (mm != 19 ? (mm-1)*20 + dd : 18*20 + dd); YY = sumDay / 260; sumDay %= 260; if(sumDay == 0) { sumDay = 260; YY--; } DD = sumDay % 13; DD = (DD == 0 ? 13 : DD);//对取模运算的细节考虑 MM = sumDay % 20; MM = (MM == 0 ? 20 : MM);//对取模运算的细节考虑 cout << DD << " " << itos[MM] << " " << YY << endl; } return 0; }