POJ 1008 Maya Calendar (模拟)
来源:互联网 发布:有没有听音识谱软件 编辑:程序博客网 时间:2024/05/17 23:31
Description
For religious purposes, the Maya used another calendar in which the year was called Tzolkin (holly year). The year was divided into thirteen periods, each 20 days long. Each day was denoted by a pair consisting of a number and the name of the day. They used 20 names: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers; both in cycles.
Notice that each day has an unambiguous description. For example, at the beginning of the year the days were described as follows:
1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, and again in the next period 8 imix, 9 ik, 10 akbal . . .
Years (both Haab and Tzolkin) were denoted by numbers 0, 1, : : : , where the number 0 was the beginning of the world. Thus, the first day was:
Haab: 0. pop 0
Tzolkin: 1 imix 0
Help professor M. A. Ya and write a program for him to convert the dates from the Haab calendar to the Tzolkin calendar.
Input
NumberOfTheDay. Month Year
The first line of the input file contains the number of the input dates in the file. The next n lines contain n dates in the Haab calendar format, each in separate line. The year is smaller then 5000.
Output
Number NameOfTheDay Year
The first line of the output file contains the number of the output dates. In the next n lines, there are dates in the Tzolkin calendar format, in the order corresponding to the input dates.
Sample Input
310. zac 00. pop 010. zac 1995
Sample Output
33 chuen
01 imix
09 cimi 2801
题意:玛雅人有两种历法,一种叫Haab,另一种叫Tzolkin。
Haab历法:一年365天 = 18个月*30天 + 1个月*5天
这19个月的名字分别是:pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu, uayet.
天则直接用数字表示。
Tzolkin历法:一年260天 = 20*13,使用20个单词和13个数字来记录日期,
单词分别是imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau
日期是这样表示的:1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, (单词进入下一个循环) 8 imix, 9 ik, 10 akbal . . .
可以看到这种历法是用单词和数字各自循环然后组合,产生260种组合,也就对应了260天。
现在我们要做的就是把输入的Haab历法转换为Tzolkin历法输出
解题思路:用map<string,int>把所有Haab历法的月份转换为数字,然后计算 总天数=365*年份+30*月份+天数
然后用 总天数/260 就可以得到Tzolkin历法的年份,总天数%260就是这年的第多少天。为了方便起见,我们先把这260天所有的表示法都用map<int,string>计算出来。
注意:这里要稍微注意下的就是起始日期。
Haab: 0. pop 0
Tzolkin: 1 imix 0
代码:
#include <iostream>#include <cmath>#include <cstdio>#include <map>#include <sstream>using namespace std;char m1[][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};char m2[][10]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};map<string,int> haab;map<int,string> tzo;string num2str(int i)//int转string{ stringstream ss; ss<<i; return ss.str();}int main(){ //把Haab历法的月份对应成0~19 for(int i=0;i<19;i++) { haab[m1[i]]=i; } //把Tzolkin历法260天每天对应的表示法计算出来 int a=0,b=1; for(int i=0;i<260;i++,a++,b++) { if(a>=20) a=0; if(b>13) b=1; string data=num2str(b)+" "+(string)m2[a]; tzo[i]=data; } int n; scanf("%d",&n); printf("%d\n",n); while(n--) { int d,y; char m[10]; scanf("%d.%s%d",&d,m,&y); int days=y*365+haab[m]*20+d; cout<<tzo[days%260]<<' '<<days/260<<endl; } return 0;}
- POJ 1008-Maya Calendar-模拟
- POJ 1008 Maya Calendar (模拟)
- POJ 1008 Maya Calendar 模拟题
- POJ 1008 Maya Calendar(模拟)
- POJ 1008 Maya Calendar(日期模拟)
- POJ 1008 Maya Calendar
- poj 1008 Maya Calendar
- POJ 1008 Maya Calendar
- POJ 1008 Maya Calendar
- 【POJ】1008 Maya Calendar
- POJ-1008:Maya Calendar
- POJ 1008 Maya Calendar
- poj 1008 Maya Calendar
- POJ-1008-Maya Calendar
- POJ-1008-Maya Calendar
- POJ 1008/Maya Calendar
- poj 1008 Maya Calendar
- poj 1008 Maya Calendar
- H5+GeoLocation获取地理位置
- 个人ubuntu安装后的操作安装顺序
- POJ 2369 Permutations (置换群)
- PHP 安装
- Spring mvc-异常javax.servlet.ServletException: Could not resolve view with name 'xxx' in servlet with
- POJ 1008 Maya Calendar (模拟)
- Android开发从0到1024基础篇(3)DataBinding
- git pull总是要输入账号和密码
- serialVersionUID
- .sh数据输出及备份过程
- 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect的问题
- iOS 在cell中使用倒计时的处理方法(新)
- C++之C语言混合编程学习笔记
- JAVA 反射一撇