题目
思路
思路就是模拟跟着走就可以了。注意在取模运算的时候,如果a mod b当a==b的时候得到的结果是0,但是这题显然我们并不想得到0,所以要判断一下。既然是两种值的判断,那就不如玩点好玩的:三目运算符。 a=(条件判断) ? 值1:值2. 跟python中的if-else很像,但是C++的比较抽象,如果条件判断为真,那么就选择值1,否则就选择值2.
AC代码
#include <bits/stdc++.h>
using namespace std;
map<int, string> Tzolkin = {
{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"},
{14, "ix"},
{15, "mem"},
{16, "cib"},
{17, "caban"},
{18, "eznab"},
{19, "canac"},
{20, "ahau"},
};
map<string, int> Haab = {
{"pop", 1},
{"no", 2},
{"zip", 3},
{"zotz", 4},
{"tzec", 5},
{"xul", 6},
{"yoxkin", 7},
{"mol", 8},
{"chen", 9},
{"yax", 10},
{"zac", 11},
{"ceh", 12},
{"mac", 13},
{"kankin", 14},
{"muan", 15},
{"pax", 16},
{"koyab", 17},
{"cumhu", 18},
};
int main() {
int n;
char month[10];
int day = 0, year = 0, month_day_sum = 0;
cin >> n;
for (int i = 1; i <= n; ++i) {
scanf("%d.%s %d", &day, month, &year);
string month_str;
for (int j = 0; month[j]; ++j) {
month_str += month[j];
}
if (month_str == "uayet") {
month_day_sum = 18 * 20;
} else {
month_day_sum = (Haab[month_str] - 1) * 20;
}
int day_sum = year * 365 + month_day_sum + day + 1;
int year_new = day_sum / 260;
int a = (day_sum - year_new * 260) % 20;
a = (a == 0) ? 20 : a;
string day_new = Tzolkin[a];
int num_new = (day_sum - year_new * 260) % 13;
num_new = (num_new == 0) ? 13 : num_new;
cout << num_new << " " << day_new << " " << year_new << endl;
}
}
收获
在调试代码的时候,发现当我们用char p[],定义一个数组的时候,cout<<p<<endl。是可以直接把p输出的; 另外就是注意取模运算的结果的0啦!
|