Source:

Description:

Input Specification:

Output Specification:

Sample Input:

Sample Output:

Keys:

  • 哈希映射

Attention:

  • getline()会吸收换行符

Code:

 /*
题目大意: */
#include<cstdio>
#include<string>
#include<map>
#include<iostream>
using namespace std;
const int M=;
map<string,int> earth;
string mars0[M]={"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string mars1[M]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE for(int i=; i<M; i++)
earth[mars0[i]]=i;
for(int i=; i<M; i++)
earth[mars1[i]]=i*M; int n;
scanf("%d\n", &n);
while(n--)
{
string s;
getline(cin,s);
if(s[]<'' || s[]>'')
{
if(s.size()==)
printf("%d\n", earth[s]);
else
printf("%d\n", earth[s.substr(,)]+earth[s.substr(,)]);
}
else
{
int num = atoi(s.c_str());
if(num%M!= && num/M!=)
printf("%s %s\n", mars1[num/M].c_str(),mars0[num%M].c_str());
else if(num/M!=)
printf("%s\n", mars1[num/M].c_str());
else
printf("%s\n", mars0[num%M].c_str());
}
} return ;
}
05-27 00:47
查看更多