北大acm1008
题目链接:
http://poj.org/problem?id=1008&lang=zh-CN&change=true
题目要求把Haab转化成Tzolkin,基本思路是根据输入算出距离第一天的天数,转化成日期。
自我感觉用的不错的是sstream,不足的是查找Haab_month的序号部分,本来觉得用了map的find应该会很方便,但map的插入一直报错,就没用。
一开始总是wrong anwser,后来发现被13整除,被20整除,被260整除,这种要特别留意加处理。
#include <iostream> #include <map> #include <string> #include <sstream> using namespace std; string Haab_month[]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"}; string Tzolkin_day[]={"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"}; int main(int argc, const char * argv[]) { int count; cin>>count; cout<<count<<endl; int i; for(int i=0;i<count;i++) { //读一行,计算一行,输出一行 float day0; string month; int year; cin>>day0>>month>>year; int day=(int)day0; //cout<<day<<endl; //cout<<month<<endl; //cout<<year<<endl; //计算日子 int day_since_start; int j; //这里查找月份对应的数字,本来用map很方便的,但是map的插入总出错 for(j=0;j<18;j++) { if(Haab_month[j]==month) { break; } else continue; } day_since_start=day+j*20+year*365+1; //cout<<day_since_start; int word1; int num1; int year1; if(day_since_start%260==0) { year1=day_since_start/260-1; }else { year1=day_since_start/260; } num1=day_since_start%13; if(num1==0)num1=13; word1=day_since_start%20; if(word1==0)word1=20; cout<<num1<<" "<<Tzolkin_day[word1-1]<<" "<<year1<<endl; } }