题名:玛雅历
题意:历法转换 。
代码:
// 1008.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include <iostream>
using namespace std;
class data
{
public:
char day[];
char mon[];
char year[];
}; int main(int argc, char* argv[])
{
int num=;
cin>>num;
char temp[]={};
data *s=new data[num];
for (int i=;i<num;i++)
{
cin>>s[i].day>>s[i].mon>>s[i].year;
}
cout<<num<<endl;
string *sday=new string[];
int tmon=,tday=;
int count=;
int o=,p=;
string ma[]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
while()//计算Tzolkin历表对应一年中的天数
{
o++;
p++;
if(o>)
o=;
if(p>)
p=;
char temp[];
sprintf(temp,"%d ",o);
sday[count]=temp;
sday[count]+=ma[p-];
count++;
if(count==)
break; }
string HaabMonDic[]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
for (int i=;i<num;i++)
{
int day=atoi(s[i].day)+;
string month=s[i].mon;
int imonth=;
string year=s[i].year;
int iyear=atoi(year.c_str());
for (int j=;j<;j++)
{
if(month.compare(HaabMonDic[j])==)
{
imonth=j;
break;
}
}
int allday=iyear*+imonth*+day;
int tyear=allday/;
int tt=allday%;
if(tt==)//如果是最后一天,需要转换
{
tyear--;
tt=;
}
printf("%s %d\n",sday[tt-].c_str(),tyear);
}
delete []sday;
delete []s;
return ; }
总结:想当然,忘记要转换的历法最后一天要特殊处理,第一种历法实际上是有19个月。马虎粗心大意,哎