1100. Mars Numbers (20)

    考查进制转换

#include 
#include 

using namespace std;

string t1[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string t2[] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};

string num2mar(int n){
	string s;

	if(n > 12){
		s = t2[n/13];

		if(n%13){
			s += " " + t1[n%13];
		}
	}else{
		s = t1[n];
	}

	return s;
}

int mar2num(string s){
	int sum = 0;
	size_t pos = s.find(' ');

	for(int i = 1; i <= 12; ++i){
		if(t2[i] == s.substr(0, pos)){
			sum = 13*i;
			break;
		}
	}

	if(pos != string::npos){
		s = s.substr(pos+1);
	}

	for(int i = 0; i < 13; ++i){
		if(t1[i] == s){
			sum += i;
			break;
		}
	}
	
	return sum;
}

int main(){
	int n;
	(cin >> n).get();

	for(int i = 0; i < n; ++i){
		char c = cin.peek();
		if(c >= '0' && c <= '9'){
			int num;
			(cin >> num).get();
			cout << num2mar(num) << endl;
		}else{
			string s;
			getline(cin, s);
			cout << mar2num(s) << endl;
		}
	}



	return 0;
}


你可能感兴趣的:(PAT(Advanced,Level))