玛雅日历转化(POJ1008, UVA300)

这个是我个人的总结,方便与解题

Haab历法

Haab历法,一年有365天。Haab历法每年有19个月,在前18个月,
每月有20天,月份的名字分别是pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu。
这些月份中的日期用0到19表示;Haab历的最后一个月叫做uayet,
它只有5天,用0到4表示。

Tzolkin历法

一年被分成13个不同的时期,每个
时期有20天,每一天用一个数字和一个单词相组合的形式来表示。
使用的数字是1~13,使用的单词共有20个,它们分别是: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 ……也就是说数字和单词各自独立循环使用

haab的月份用特定的字母表示,天数用数字表示

Tzolkin的月份用数字表示,天数用数字表示1-13,并且使用20单词

思路

  1. 求出haab日历中的天数,因为两个日历惟一的共同点,就是从世界开始的那一天算起的
  2. 按照这个思路走,先求年%260(求余)
  3. 再求月
  4. 求天数,并且求出数字代表的特定的单词

以下是原题(建议打开谷歌翻译)

Maya Calendar , POJ1008, UVA300

Description

During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day long year, called Haab, which had 19 months. Each of the first 18 months was 20 days long, and the names of the months were pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu. Instead of having names, the days of the months were denoted by numbers starting from 0 to 19. The last month of Haab was called uayet and had 5 days denoted by numbers 0, 1, 2, 3, 4. The Maya believed that this month was unlucky, the court of justice was not in session, the trade stopped, people did not even sweep the floor.

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

The date in Haab is given in the following format:

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

The date in Tzolkin should be in the following format:

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 1

5
10. zac 0
0. pop 0
10. zac 1995
19. muan 2021
13. koyab 2002

Sample Output 1

5
3 chuen 0
1 imix 0
9 cimi 2801
7 chicchan 2838
9 kan 2811

源代码

#include <iostream>
#include <stdio.h>
using namespace std;
// 总结
// haab的月份用特定的字母表示,天数用数字表示
// Tzolkin的月份用数字表示,天数用数字表示1-13,并且使用20单词
// 我晕为什么不用1-20来表示,我服
/* 定义Haab的19个月 因为c语言是没有string类型,所以想用scanf会出错想用scanf的话,可以将string类改成 char具体的操作为 char Haab[19][10]*/
string Haab[19] = {"pop", "no", "zip", "zotz","tzec", "xul", "yoxkin", "mol", "chen", "yax","zac", "ceh", "mac", "kankin", "muan", "pax","koyab", "cumhu", "uayet"};
/* 定义Tzolkin的20天*/
string Tzolkin[20] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi","manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix",                        "mem","cib", "caban", "eznab", "canac", "ahau"};
// 日期表示的信息
struct Data
{int Date;//string类型的monthstring Month;int Year;
};
//日期转换函数
void convert(Data &x);
int main()
{int i, n;char ch; //储存.字符//输入的第一行表示要转化的日期数量n// scanf("%d", &n);cin>>n;//创建一个一维数组Data *p = new Data[n];for (int i = 0; i < n; i++){//为什么scanf和cin输入方式不同就有着这么大的差别// scanf("%d. %s %d", &p[i].Date, &p[i].Month, &p[i].Year);cin>>p[i].Date>>ch>>p[i].Month>>p[i].Year;}printf("%d\n", n);for (int i = 0; i < n; i++){convert(p[i]);}system("pause");return 0;
}
void convert(Data &x)
{//代表从世界开始记起的天数long current;//代表月份int month;//寻找haab月份代表是那个数字for (month = 0; month < 20; month++) //当前月份是Haab历的哪个月{if (x.Month == Haab[month])break;}current = x.Year * 365 + month * 20 + x.Date + 1;int num, year = 0; /* num为输出中的数字,year为输出中的年份 */string word;       /* 月份名称 *///求月份的时候会遇到两种情况/* 余数为0则为一个整月num=13余数不为零则月数等于余数*/if (current % 13 == 0){num = 13; //}else{num = current % 13;}//求年份/* 减260天即可 */while ((current - 260) > 0){++year;current -= 260;}//开始判断天数//如果天数=0说明是上一年的最后一天if (current == 0){word = "ahau";}else{//除以20继续判断current = current % 20;//和之前判断天数一样if (current == 0){word = "ahau"; /* 表示前一个月的最后一天 */}else{word = Tzolkin[current - 1];}// printf("%d %s %d\n",num,word,year);cout<<num<<" "<<word<<" "<<year<<endl;}
}

玛雅日历转化(Maya calendar,POJ1008, UVA300)相关推荐

  1. POJ1008 Maya Calendar

    题目来源:http://poj.org/problem?id=1008 题目大意: Maya人认为一年有365天,但他们有两种日历.一种叫做Haab,有19个月.前18个月每月20天,每个月的名字分别 ...

  2. POJ - 1008 Maya Calendar

    简单模拟,现将第一种日历表示的天数计算出来,再转换为第二种日历.注意边写边检查 POJ - 1008Maya Calendar Time Limit: 1000MS Memory Limit: 100 ...

  3. 百炼1008:Maya Calendar

    描述 During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya cal ...

  4. python日历模块_Python calendar日历模块的说明

    calendar(日历)模块,默认每周第一天是星期一,最后一天是星期天. 函数及描述 1. calendar.calendar(year, w=2, l=1, c=6, m=3) 返回一个多行字符串格 ...

  5. layui日历和tui.calendar日程表联动

    效果演示 引用的layui.all.js有所改动,所以需另外下载 layui日历和tui.calendar日程表联动资源链接 页面源码: <!DOCTYPE html> <html ...

  6. 电子日历HTML布局,calendar日历使用

    java中的Calendar如何使用的? Java中日历类(CalendarClass)的用途? Java中日历类(Calendar类)的用途如下: Calendar类的静态方法getInstance ...

  7. java电脑日历_Java中calendar对万年历的制作(同步电脑上的万年历日期格式)

    Java编程中calendar对万年历的制作教程 使用到的方法: 1.日期类型的转换: String----->Date String str = "2020年05月27日 20:28 ...

  8. android 一年日历,android中Calendar与Date的区别 转自网络

    Android中Calendar与Date的区别以及消除时区对日期操作影响的方法 在Android中的日期操作常用的有三种方式,分别是: Date类型 Calendar类型 Unix时间戳 其中,Un ...

  9. java日历教程_JAVA Calendar方法使用基础教程详解

    究竟什么是一个 Calendar 呢?中文的翻译就是日历,那我们立刻可以想到我们生活中有阳(公)历.阴(农)历之分.它们的区别在哪呢? 比如有: 月份的定义 – 阳`(公)历 一年12 个月,每个月的 ...

  10. java中日历类:Calendar

    Calendar日历类 该类为抽象类,将所有可能用到的时间信息封装为静态成员变量,方便获取时间属性,其位于java.util.Calendar, 其中的getInstance方法可以返回一个Calen ...

最新文章

  1. Go 知识点(14) — Go 多协程(单个协程触发panic会导致其它所有协程挂掉,每个协程只能捕获到自己的 panic 不能捕获其它协程)
  2. layui一个表格中怎么接两个接口的值_layer学习笔记之table表格引入数据实现分页...
  3. AI 技术与人类主体想象 ——基于人工直觉在线讨论的研究
  4. 第 5 章 第二个 activity
  5. mysql mask from v2_MySQLDMB监控备份系统更新至v2.2
  6. cocos2d-x-3.x 动作(5)序列动作
  7. 机器学习接口代码之 Ridge、Lasso、Elasitc Net
  8. 手机User-Agent大全(Android爬虫)
  9. 我为什么不喜欢网赚和SEO
  10. eclipse alt+/ 无效时,如何设置 《转》
  11. 20年前的中国人怎么做3A大作?
  12. js中什么是事件气泡,如何阻止事件气泡
  13. 【数据湖Hudi的概念】Table Types、Indexing和Metadata Table
  14. 骨传导有什么品牌,骨传导耳机品牌推荐
  15. 独家 | 放弃Jupyter Notebooks吧,教你如何用仪表板展示研究成果
  16. 量化交易---主要流程---003
  17. 自动调节式防涝井盖设计
  18. Android 自定义下拉列表
  19. python 内建排序 HOW TO
  20. Windows server 2012 服务器挂载NAS盘

热门文章

  1. 什么是私有云、公有云、混合云?什么是云计算管理平台?
  2. 到极地拍摄北极熊 你需要这样的装备
  3. 毕业即失业,转行软件测试的辛酸泪只有自己知道
  4. 基于javaweb的企业员工绩效工资管理系统(java+springboot+freemarker+mysql)
  5. Android_CTF: kgb_messenger
  6. 灵性图书馆:好书推荐-《当下的力量》
  7. vue.js毕业设计,基于vue.js前后端分离在线教育视频点播系统设计与实现(H5移动项目)
  8. Linux编程起步 GCC基本用法
  9. 苹果开发者账号申请需要注意的三要素
  10. jemter ramp-up