POJ 1008 解题报告 Maya Calendar

还是要细心啊,题目不难,历法转换。

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;
}
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值