poj 1008

题目大意:玛雅人有两种日历,每种有不同的记法,给出其中一种起初另一种的表示。

思路:就是把日期转换成距离0年第一天的天数,再根据这个算出另一种日历的日期。

此题水,直接粘代码:

1008Accepted764K16MSG++1088B

#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

string H[19] = {
	"pop", "no", "zip", "zotz", "tzec", 
	"xul", "yoxkin", "mol", "chen", "yax",
	"zac", "ceh", "mac", "kankin", "muan",
	"pax", "koyab", "cumhu", "uayet"
};
string T[20] = {
	"imix", "ik", "akbal", "kan", "chicchan",
	"cimi", "manik", "lamat", "muluk", "ok", 
	"chuen", "eb", "ben", "ix", "mem", 
	"cib", "caban", "eznab", "canac", "ahau"
};					

int main() {
	//freopen("F:\\workspace\\sublime\\poj1008.in","r", stdin);
	int cs,num;
	string dd,mm,yy;
	scanf("%d",&cs);
	printf("%d\n",cs);
	while(cs--)
	{
		cin >> dd >> mm >> yy;
		int len = dd.length();
		dd[len - 1] = '\0';//去掉数字后边的点
		num = atoi(yy.c_str()) * 365 + atoi(dd.c_str()) + 1;
		for(int i=0; i<19; ++i)
		{
			if(mm == H[i])  num += i * 20; 
		}
		int aaa = num % 260;
		int ddd = aaa % 13;
		int mmm = aaa % 20;
		if(aaa == 0) cout << "13 ahau " << num/260-1 << endl;
		else cout << (ddd?ddd:13) << " " << T[mmm?(mmm-1):19] << " " << num/260 << endl;
	}
	return 0;
}

此题用纯c写出来更简洁,处理的那部分比我写的好多了。转自: http://www.slyar.com/blog/poj-1008-c.html

1008Accepted164K16MSC743B

#include<stdio.h>
#include<string.h>
 
char H[20][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char T[22][10]={"ahau","imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac"};
 
int main()
{
	int d, y, n, i;
	char m[20];
	scanf("%d", &n);
	getchar();
	printf("%d\n", n);
	while(n--)
	{
		scanf("%d. %s %d", &d, m, &y);
		for (i = 0; i < 18; i++)
		{
			if (strcmp(m, H[i]) == 0) break;
		}
		/* 计算一共经过了多少天 */
		d += i * 20 + y * 365;
		/* 按新历法规则输出 */
		printf("%d %s %d\n", d % 13 + 1, T[(d + 1) % 20], d / 260);
	}
	//system("pause");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值