[POJ] #1008# Maya Calendar : 字符处理/同余问题
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 74085 | Accepted: 22819 |
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
3
10. zac 0
0. pop 0
10. zac 1995
Sample Output
3
3 chuen 0
1 imix 0
9 cimi 2801
Source
- 玛雅文明有两种年历
- Haab
- 一年365天
- 19个月:
- 前18个月,每月20天;第19个月5天
- 表示方法: 0. pop 0
- 0.: 某月的某天, 从0开始计数
- pop: 月的字符表示
- 0: 年, 从0开始计数
- Tzolkin
- 一年260天
- 13个周期
- 每个周期20天
- 表示方法: 1 imix 0
- 1: 某个周期的某天,从1开始计数
- imix: 周期的字符表示
- 0: 年,从0开始计数
- Haab
- 给出某年某月某日的Haab表示
- 输出对应的Tzolkin表示
三. 分析
- 算法核心: 字符处理/同余问题
- 实现细节:
- 将Haab表示的日期,转换为从开始到当前日期的总天数
- 根据Tzolkin的表示方法
- 对总周期数(13) 取余数
- 对每个周期的天数(20) 取余数, 利用其为索引获取其对应的字符表示
- 对每年的天数(269) 取余数
四. 题解
#include <stdio.h> #define H_MONTHS 19
#define H_MONTH_DAYS 20
#define H_YEAR_DAYS 365
#define H_MONTH_LEN 7 #define T_PERIODS 13
#define T_CYCLES 20
#define T_DAYS 260 char* hms[H_MONTHS] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin",
"mol", "chen", "yax", "zac", "ceh", "mac", "kankin",
"muan", "pax", "koyab", "cumhu","uayet"}; char* tds[T_CYCLES] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik",
"lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem",
"cib", "caban", "eznab", "canac", "ahau"}; int mystrcmp(const char *str1, const char *str2)
{
while (*str1 == *str2) {
if (*str1 == '\0') return ;
str1++; str2++;
} return *str1 - *str2;
} int shmonth_to_hmonth(const char *shmonth)
{
long i = ;
for (i = ; i < H_MONTHS; i++)
if ( == mystrcmp(shmonth, hms[i])) return i; return i;
} int main(void)
{
int i, N;
int hday, hmonth, hyear; scanf("%d\n", &N);
printf("%d\n", N); for (i = ; i < N; i++) {
int days = ;
char shmonth[H_MONTH_LEN]; scanf("%d. %s %d\n", &hday, shmonth, &hyear);
hmonth = shmonth_to_hmonth(shmonth); days = hyear * H_YEAR_DAYS + hmonth * H_MONTH_DAYS + hday; printf("%d %s %d\n", days % T_PERIODS + ,
tds[days % T_CYCLES],
days / T_DAYS);
} return ;
}
[POJ] #1008# Maya Calendar : 字符处理/同余问题的更多相关文章
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 1008 Maya Calendar
链接:http://poj.org/problem?id=1008 Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- [POJ 1008] Maya Calendar C++解题
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62297 Accepted: 192 ...
- POJ 1008 Maya Calendar / UVA 300【日期转换/常量数组】
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 82431 Accepted: 25319 Descr ...
- Poj OpenJudge 百练 Bailian 1008 Maya Calendar
1.Link: http://poj.org/problem?id=1008 http://bailian.openjudge.cn/practice/1008/ 2.content: Maya Ca ...
- 【POJ】1008 Maya Calendar
参考:https://blog.csdn.net/u011392408/article/details/28866779 https://blog.csdn.net/qq_36424540/artic ...
- Poj Maya Calendar
http://poj.org/problem?id=1008 Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- Maya Calendar 分类: POJ 2015-06-11 21:44 12人阅读 评论(0) 收藏
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 70016 Accepted: 21547 D ...
- POJ1008 Maya Calendar
题目来源:http://poj.org/problem?id=1008 题目大意: Maya人认为一年有365天,但他们有两种日历.一种叫做Haab,有19个月.前18个月每月20天,每个月的名字分别 ...
随机推荐
- eclipse ADT下载地址
adt not vpn https://dl.google.com/android/eclipse/ 或 https://dl-ssl.google.com/android/eclipse/ andr ...
- Unix/Linux 关机命令
关机命令 AIX shutdown now Solaris init 5 Redhat shutdown now Centos shutdown now
- HNOI2008题目总结
呜呼..NOI前一个月正式开始切BZOJ了……以后的题解可能不会像之前的零散风格了,一套题我会集中起来发,遇到一些需要展开总结的东西我会另开文章详细介绍. 用了一天的时间把HNOI2008这套题切了… ...
- 【笨嘴拙舌WINDOWS】tagTEXTMETRIC结构
tagTEXTMETRIC用于定义在window输出文字时字的大小,其结构如下: 我在窗体上写了两句话,来详细解剖该结构(在MM_TEXT模式下输出) tmHeight表示一行文字的高度.改例中值为1 ...
- Mybatis返回插入的主键
在使用MyBatis做持久层时,insert语句默认是不返回记录的主键值,而是返回插入的记录条数:如果业务层需要得到记录的主键时,可以通过配置的方式来完成这个功能 情景一:针对自增主键的表,在插入时不 ...
- 在eclipse如何删除无效的maven build
在Eclipse的maven项目中,点击一次“maven build...”明明没有配置,它也就会产生一个maven build,那么如何删除这些无效的配置呢?
- 将js对象转为json对象属性加上引号
工具地址 http://js2json.mengxiangchaoren.com
- [Swift 语法点滴]——元组
注意:元组是否每一项加元组名非常重要,加与不加是完全不同的数据类型. 比如:var iPlayer=(name:"李逍遥",life:1000,attack:35) 将iPlaye ...
- BZOJ 1076 奖励关
注意几点: 1.为什么要逆推?由此状态可以轻易算出彼状态是否可行,而彼状态却无法轻易还原为此状态. 2.为什么可以逆推?假设时光倒流了....23333 3.注意位运算的准确,大胆写方程. #incl ...
- LeetCode Linked List Cycle II 单链表环2 (找循环起点)
题意:给一个单链表,若其有环,返回环的开始处指针,若无环返回NULL. 思路: (1)依然用两个指针的追赶来判断是否有环.在确定有环了之后,指针1跑的路程是指针2的一半,而且他们曾经跑过一段重叠的路( ...