题目大意:玛雅人有两种日历,每种有不同的记法,给出其中一种起初另一种的表示。
思路:就是把日期转换成距离0年第一天的天数,再根据这个算出另一种日历的日期。
此题水,直接粘代码:
1008 | Accepted | 764K | 16MS | G++ | 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
1008 | Accepted | 164K | 16MS | C | 743B |
#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;
}