POJ-1008-模拟

题意:给出两种日历,然后做一个日历转换

思路:直接模拟,仔细一点就能过。

主要是记录一个Bug:

WA代码:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    string ha[] = { "pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet" };
    string tz[] = { "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau" };
    int t;  cin >> t;   char doc;
    cout << t << endl;
    while(t--)
    {
        int day, year;  string month;
        cin >> day >> doc >> month >> year;
        day ++;
        int sum_day = day + year * 365;
        for(int i = 0; i < 19; i++)
        {
            if(ha[i] == month)
            {
                sum_day += 20 * i;
                break;
            }
        }
        cout << sum_day % 13 << " " << tz[sum_day % 20] << " " << sum_day / 260 << endl;
    }
    return 0;
}
/*
    Haab历: 365天
        19个月, 用 19 个单词表示,开始的18月中有20天,用0 ~ 19表示 最后一个月只有5天,用 0 ~ 4 表示。
        月份:pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu, uayet
        天数:0 ~ 19, 0 ~ 4
    Tzolkin历:260天
        13个月, 用 1 ~ 13 表示, 每个月有20天, 用 20个单词 循环表示
        月份: 1 ~ 13
        天数: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau
    
        10.zac 0 ==> 3 chuen 0
        10 * 20 + 11 == 211
*/

 

AC代码:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    string ha[] = { "pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet" };
    string tz[] = { "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau" };
    int t;  cin >> t;   char doc;
    cout << t << endl;
    while(t--)
    {
        int day, year;  string month;
        cin >> day >> doc >> month >> year;
        int sum_day = day + year * 365;
        for(int i = 0; i < 19; i++)
        {
            if(ha[i] == month)
            {
                sum_day += 20 * i;
                break;
            }
        }
        cout << sum_day % 13 + 1 << " " << tz[sum_day % 20] << " " << sum_day / 260 << endl;
    }
    return 0;
}
/*
    Haab历: 365天
        19个月, 用 19 个单词表示,开始的18月中有20天,用0 ~ 19表示 最后一个月只有5天,用 0 ~ 4 表示。
        月份:pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu, uayet
        天数:0 ~ 19, 0 ~ 4
    Tzolkin历:260天
        13个月, 用 1 ~ 13 表示, 每个月有20天, 用 20个单词 循环表示
        月份: 1 ~ 13
        天数: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau
    
        10.zac 0 ==> 3 chuen 0
        10 * 20 + 11 == 211
*/

WA代码与AC代码的主要区别在于求日期,AC代码是最后来对日期+1,因为是从0~19计数,转化为1~13计数,我们就需要对它做一个变换,放在最后加1,那么放在最后加1与在前面加1到底有什么区别呢,一个很简单的区别在于答案取模后无法取到13。

posted @ 2020-09-01 16:45  ACM-Epoch  阅读(132)  评论(0编辑  收藏  举报