TOJ1002

http://acm.tju.edu.cn/toj/showp1002.html

解决思路:

这是一道较简单的数制度转换题,首先计算某Haab历距离世界开始时的天数,再通过计算得到的天数,转换成相应的Tzolkin日期。

我个人的问题在于,对字符串string和char的理解不深刻,好多知识都忘了……求Tzolkin对应的年月日不难,感觉我碰到的问题在于输入cin的语法,年、月、日,分开输入即可,不需要放到一个字符串里,反而是给自己增加困难……

代码:

#include 
using namespace std;

string Haab[18] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu"};
string Tzolkin[20] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};

int getMonth(string month){
	for(int i = 0; i < 18; i++){
		if(month == Haab[i])
			return i;
	}
}

int main(){
	int n;
	cin >> n;
	cout << n << endl;
	int day, year;
	char doc;
	string month;
	while(n--){
		cin >> day >> doc >> month >> year;
		int sum = year*365 + getMonth(month)*20 + day;
		int number = sum % 13 + 1;
		int Tzolkin_index = sum % 20;
		int Tzolkin_year = sum/260;
		cout << number << " " << Tzolkin[Tzolkin_index] << " " << Tzolkin_year << endl;
	}
	return 0;
}

 

你可能感兴趣的:(ACM刷题)