还是要细心啊,题目不难,历法转换。
AC吧,这么简单的题烧这么长时间。。。丢人了。。。。
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
int getTotalDays(string&, string&, string&);
string& turnHolly(int, string&);
int main ()
{
int iCount;
cin >> iCount;
cout << iCount << endl;
string strDayHaab;
string strMonthHaab;
string strYearHaab;
int iTotalDays;
while (iCount --)
{
cin >> strDayHaab >> strMonthHaab >> strYearHaab;
strDayHaab = strDayHaab.substr(0, strDayHaab.find("."));
iTotalDays = getTotalDays(strDayHaab, strMonthHaab, strYearHaab);
string strResult = "";
cout << turnHolly(iTotalDays, strResult) << endl;
}
return 0;
}
int getTotalDays(string& strDayHaab, string& strMonthHaab, string& strYearHaab)
{
int iTotalDays = atoi(strDayHaab.c_str());
if ("pop" == strMonthHaab)
{
}
else if ("no" == strMonthHaab)
{
iTotalDays += 1*20;
}
else if ("zip" == strMonthHaab)
{
iTotalDays += 2*20;
}
else if ("zotz" == strMonthHaab)
{
iTotalDays += 3*20;
}
else if ("tzec" == strMonthHaab)
{
iTotalDays += 4*20;
}
else if ("xul" == strMonthHaab)
{
iTotalDays += 5*20;
}
else if ("yoxkin" == strMonthHaab)
{
iTotalDays += 6*20;
}
else if ("mol" == strMonthHaab)
{
iTotalDays += 7*20;
}
else if ("chen" == strMonthHaab)
{
iTotalDays += 8*20;
}
else if ("yax" == strMonthHaab)
{
iTotalDays += 9*20;
}
else if ("zac" == strMonthHaab)
{
iTotalDays += 10*20;
}
else if ("ceh" == strMonthHaab)
{
iTotalDays += 11*20;
}
else if ("mac" == strMonthHaab)
{
iTotalDays += 12*20;
}
else if ("kankin" == strMonthHaab)
{
iTotalDays += 13*20;
}
else if ("muan" == strMonthHaab)
{
iTotalDays += 14*20;
}
else if ("pax" == strMonthHaab)
{
iTotalDays += 15*20;
}
else if ("koyab" == strMonthHaab)
{
iTotalDays += 16*20;
}
else if ("cumhu" == strMonthHaab)
{
iTotalDays += 17*20;
}
else if ("uayet" == strMonthHaab)
{
iTotalDays += 18*20;
}
else {
cout << "Month count wrong!" << endl;
}
iTotalDays += 365 * atoi(strYearHaab.c_str());
return iTotalDays;
}
string& turnHolly(int iTotalDays, string& strR)
{
char cTemp[32];
sprintf(cTemp, "%d", iTotalDays % 260 % 13 + 1);
strR = string(cTemp);
switch((iTotalDays % 260) % 20)
{
case 0:
strR.insert(strR.size(), " imix ");
break;
case 1:
strR.insert(strR.size(), " ik ");
break;
case 2:
strR.insert(strR.size(), " akbal ");
break;
case 3:
strR.insert(strR.size(), " kan ");
break;
case 4:
strR.insert(strR.size(), " chicchan ");
break;
case 5:
strR.insert(strR.size(), " cimi ");
break;
case 6:
strR.insert(strR.size(), " manik ");
break;
case 7:
strR.insert(strR.size(), " lamat ");
break;
case 8:
strR.insert(strR.size(), " muluk ");
break;
case 9:
strR.insert(strR.size(), " ok ");
break;
case 10:
strR.insert(strR.size(), " chuen ");
break;
case 11:
strR.insert(strR.size(), " eb ");
break;
case 12:
strR.insert(strR.size(), " ben ");
break;
case 13:
strR.insert(strR.size(), " ix ");
break;
case 14:
strR.insert(strR.size(), " mem ");
break;
case 15:
strR.insert(strR.size(), " cib ");
break;
case 16:
strR.insert(strR.size(), " caban ");
break;
case 17:
strR.insert(strR.size(), " eznab ");
break;
case 18:
strR.insert(strR.size(), " canac ");
break;
case 19:
strR.insert(strR.size(), " ahau ");
break;
}
sprintf(cTemp, "%d", (int)(iTotalDays / 260));
strR += string(cTemp);
return strR;
}