poj 1008 Maya Calendar

//题意:玛雅人有两种计算年的,方法1):一年19个月,前18个月20天,弟19个月5天,共365天,每个月有自己的英文代号,天数、年份下标从0开始;方法2):一年分为13个月,每个月20天,共260天,每天有自己的英文代号;给出方法1中的某一天让你转换为方法二的某一天。输入:方法一的的    天数下标. 月份代号 年份下标    输出:数字(从1~13循环输出) 天的英文代号 年份下标(【注意】:这个输出很奇怪要求,第一个数字从1~13循环输出  天的英文代号  年份) 

//思路:找到对应规律很简单,然后主要通过map将月份或者天数的代号和数字对应起来,当然注意一个东西,比如今年是弟0年,今年最后一天对应的年份还是0,这里当时wa了一次

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

//建立映射用map数组
map <string, int> mp;
map <int, string>mp1;

//初始化数组用map很方便
void init()
{
    string s[] = {
         "pop", "no", "zip", "zotz", "tzec", "xul",
         "yoxkin", "mol", "chen", "yax", "zac", "ceh",
         "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"
    };
    string s1[] = {
         "imix", "ik", "akbal", "kan", "chicchan", "cimi",
         "manik", "lamat", "muluk", "ok", "chuen", "eb",
         "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"
    };
    for(int i = 0; i < 19; i++){
        mp[s[i]] = i;
    }
    int j = 0;
    while(j<20){
        mp1[j] = s1[j];
        j++;
    }
    return ;
}

int main()
{
    int t;
    init();
    while(scanf("%d", &t) != EOF){
        printf("%d\n", t);
        getchar();
        while(t--){

            char str[20];
            char c;
            int index_dot, second_space, len = 0, day = 0, year = 0;
            string s;
            
            //输入
            while(1){
                scanf("%c", &c);
                if(c == '\n')
                    break;
                else if(c == '.')
                    index_dot = len;
                else if(c == ' ')
                    second_space = len;
                str[len++] = c;
            }
            
            //将字符串截取获得int 和 字符串
            for(int i = 0; i < index_dot; i++){
                day = day*10 + (str[i]-'0');
            }
            for(int i = second_space+1; i < len; i++){
                year = year*10 + (str[i]-'0');
            }
            for(int i = index_dot+2, j = 0; i < second_space; i++,j++){
                s += str[i];
            }

            //计算
            int month1, year1, day1, t;
            t = year*365 + 20*mp[s] + day + 1;
            month1 = t%13 == 0 ? 13 : t%13;
            year1 = t%260 == 0 ? t/260-1 : t/260;
            day1 = t%20 == 0 ? 19 : t%20-1;
            printf("%d ", month1);
            cout << mp1[day1] << " ";
            printf("%d\n", year1);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值