[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天,每个月的名字分别 ...
随机推荐
- R之pryr
1. Pryr安装 由于项目pryr,还没有发布到CRAN,仅支持从github安装.要使用devtools包来通过github来安装,在https://github.com/hadley/pryr中 ...
- mvp(2)一个简单示例,加深理解
参考: http://www.cnblogs.com/liuling/p/mvp-pattern-android.html 架构图: 1.View层 public interface NewsView ...
- Evaluate Reverse Polish Notation(堆栈)
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- hadoop优点和缺点
l扩容能力(Scalable):能可靠地(reliably)存储和处理千兆字节(PB)数据. l成本低(Economical):可以通过普通机器组成的服务器群来分发以及处理数据.这些服务器群总计可达数 ...
- JAVA反射技术的使用
前言 在开发html使用jquery提交post的时候,可以使用jquery遍历from元素里面的input元素实现参数组合,这样就不用手动打参数了,特别是在参数很多的时候,费神费时. 我开发Andr ...
- 8皇后以及N皇后算法探究,回溯算法的JAVA实现,递归方案
八皇后问题,是一个古老而著名的问题,是回溯算法的典型案例.该问题是国际西洋棋棋手马克斯·贝瑟尔于1848年提出:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同 ...
- 如何在linux中从源代码编译安装nodejs?
$ sudo yum groupinstall 'Development Tools'安装开发环境$ wget https://nodejs.org/dist/v0.12.2/node-v0.12.2 ...
- bzoj1564: [NOI2009]二叉查找树
dp. 首先这棵树是一个treap. 权值我们可以改成任意实数,所以权值只表示相互之间的大小关系,可以离散化. 树的中序遍历是肯定确定的. 用f[l][r][w]表示中序遍历为l到r,根的权值必须大于 ...
- 使用C++读写Excel
1.导入Excel类型库 使用Visual C++的扩展指令#import导入Excel类型库: 1 2 3 4 5 6 7 8 9 10 11 12 #import "C:\\Progra ...
- 想找个计算器当本命?来试试UWP应用《纸书科学计算器》
久违了.上次在博客园发文还是4年前,正是高中参加NOIP的时候.这4年里发生了很多事,乃至再次看到过去的文章时,仿佛看到了自己也不熟悉的风景.最近很想把我的博客重新拾起来,慢慢灌溉,写一些微不足道的技 ...