代码改变世界

POJ 1008 Maya Calendar 模拟题

2012-08-22 11:30  javaspring  阅读(224)  评论(0编辑  收藏  举报

来源:http://poj.org/problem?id=1008

题意:首先给你一种旧的玛雅日历法,然后再给你一种新的历法。让求原来旧的玛雅历法的某年某月某日等于新的历法的第几年,第几天。

思路:简单模拟题目,仔细读题,按照题目的意思,一点一点写就可以了。注意一点是新的天数不能为0,若求出的新天数为0,则实际上应该是13.

代码:

#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
using namespace std;

int num[14] = {0,1,8,2,9,3,10,4,11,5,12,6,13,7};
string ss[21] = {"0","pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"};
string newss[21] = {"0","imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
int fun(int day,string month,int year){
	int mm = 0;
	for(int i = 1; i <= 20; ++i){
		if(month == ss[i]){
		  mm = i;
		  break;
		}
	}
	return year * 365 + (mm - 1) * 20 + day ;
}
int main(){
	//freopen("1.txt","r",stdin);
	int numcase;
	scanf("%d",&numcase);
	printf("%d\n",numcase);
	for(int ca = 1; ca <= numcase; ++ca ){
	  int day,year;
	  string month;
	  scanf("%d.",&day);
	  cin >> month;
	  scanf("%d",&year);
	  int sum1 = fun(day,month,year);
	  int newyear = sum1 / 260;
	  int newmm = (sum1 - newyear * 260) / 20;
	  newmm++;
	  int newday = (sum1 - newyear * 260) % 20;
	  string newmonth;
	  newmonth = newss[newday+1];
	  newday = (num[newmm] + newday ) % 13;
	  if(newday == 0) newday = 13;
	  printf("%d ",newday);
	  cout<<newmonth;
	  printf(" %d\n",newyear);
	}
	return  0;
}