PAT乙级1044 火星数字 (20 分)
Posted 辉小歌
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT乙级1044 火星数字 (20 分)相关的知识,希望对你有一定的参考价值。
#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<sstream>
#include<map>
using namespace std;
map<string,int>n,m;
string n1[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string m1[20]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int main()
{
for(int i=0;i<=12;i++) n[n1[i]]=i;
for(int i=1;i<=12;i++) m[m1[i]]=i;
int k; cin>>k;
string s; getline(cin,s);
while(k--)
{
getline(cin,s);
if(s[0]>='0'&&s[0]<='9')
{
int a=stoi(s);
vector<int> ve;
if(a==0) ve.push_back(0);//特殊情况
while(a)
{
int t=a%13;
ve.push_back(t);
a=a/13;
}
if(ve.size()==1) cout<<n1[ve[0]]<<endl;
else
{
if(ve[0]==0) cout<<m1[ve[1]]<<endl;
else cout<<m1[ve[1]]<<" "<<n1[ve[0]]<<endl;
}
}
else
{
stringstream l(s);
string x;
vector<string> ve;
while(l>>x) ve.push_back(x);
int sum=0;
if(ve.size()==1)
{
for(int i=0;i<13;i++) if(n1[i]==ve[0]) sum=i;
for(int i=1;i<13;i++) if(m1[i]==ve[0]) sum=i*13;
}
else sum=m[ve[0]]*13+n[ve[1]];
cout<<sum<<endl;
}
}
return 0;
}
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
string a[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string b[20]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int main(void)
{
int n; cin>>n;
string s; getline(cin,s);
for(int i=0;i<n;i++)
{
getline(cin,s);
if(s[0]>='0'&&s[0]<='9')
{
int temp=stoi(s);
if(temp<=12) cout<<a[temp]<<endl;
else if(temp&&temp%13==0) cout<<b[temp/13]<<endl;
else cout<<b[temp/13]<<" "<<a[temp%13]<<endl;
}
else
{
vector<string> ve;
stringstream l(s);
string x;
while(l>>x) ve.push_back(x);
int ans=0;
if(ve.size()==1)
{
for(int i=0;i<=12;i++) if(ve[0]==a[i]) ans=i;
for(int i=0;i<=12;i++) if(ve[0]==b[i]) ans=i*13;
}
else
{
for(int i=1;i<=12;i++) if(ve[0]==b[i]) ans=i*13;
for(int i=0;i<=12;i++) if(ve[1]==a[i]) ans+=i;
}
cout<<ans<<endl;
}
}
return 0;
}
以上是关于PAT乙级1044 火星数字 (20 分)的主要内容,如果未能解决你的问题,请参考以下文章