PAT甲级 Mars Numbers(20分)

\quad 水题,但是注意0表示tret,需注意。

#include 
using namespace std;

string one[12] = {"jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string two[12] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	string s;
	getchar();
    for (int i = 0; i < n; ++i)
    {
    	getline(cin, s);
    	if(s=="0")
    	{
    		cout << "tret" << endl;
    		continue;
    	}
    	if(s[0]>='0' && s[0]<='9')
    	{
    		int temp = 0;
    		for (int j = 0; j < s.length(); ++j)
    		{
    			temp += (s[j]-'0')*pow(10, s.length()-j-1)+0.01;
    		}
    		int high = temp/13;
    		int low = temp%13;
    		if(high)
    		{
    			cout << two[high-1];
    			if(low) cout << " ";
    			else cout << endl;
    		}
    		if(low)
    		{
    			cout << one[low-1] << endl;
    		}
    	}
    	else
    	{
    		int flag = s.find(' ');
    		int res = 0;
    		if(flag!=-1)
    		{
    			string high = s.substr(0, flag);
    			string low = s.substr(flag+1);
    			for (int j = 0; j < 12; ++j)
    			{
    				if(two[j]==high) res+=(j+1)*13;
    			}
    			for (int j = 0; j < 12; ++j)
    			{
    				if(one[j]==low) res+=j+1;
    			}
    			cout << res << endl;
    		}
    		else
    		{
    			bool find = false;
    			for (int j = 0; j < 12; ++j)
    			{
    				if(one[j]==s) 
    				{
    					res+=j+1;
    					find = true;
    				}
    			}
    			if(!find)
    			{
    				for (int j = 0; j < 12; ++j)
	    			{
	    				if(two[j]==s) res+=(j+1)*13;
	    			}
    			}
    			cout << res << endl;
    		}
    	}
    }
	return 0;
}

你可能感兴趣的:(PAT甲级)