来源:http://poj.org/problem?id=1008
这题没什么的,先算出总的天数,再算出另一种日历的表示就是了,没什么技巧可言。
需要注意的是一个特殊的数据:
4. uayet 259 ,应输出13 ahau 364
基本上样例过了,再把上面的特殊数据过了就行了。
#include <iostream> #include <cstdio> #include <string> #include <cstring> using namespace std; const char hmonth[19][10] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"}; const string tday[20] = { "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau" }; int find(char *month) { for (int i=0; i<20; i++) if (!strcmp(month, hmonth[i])) return i; } int main() { int ncase; cin>>ncase; cout<<ncase<<endl; int day, year; char ch; char month[10]; for (int i=0; i<ncase; i++) { scanf("%d. %s%d", &day, &month, &year); int imonth = find(month); int sumday = year*365 + imonth*20 + day+1; int tyear = (sumday-1) / 260; //这里要-1,不然/运算有可能出错 sumday -= tyear*260; int ttday = sumday - (sumday / 13)*13; if (ttday == 0) ttday = 13; int tmonth = sumday - (sumday / 20) * 20; if (tmonth == 0) tmonth = 20; cout<<ttday<<" "<<tday[tmonth-1]<<" "<<tyear<<endl; } return 0; }