设立数组对应会更方便,不要一个一个对应的打进去
string mar{13}= {jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec}
我是怎么写出这么蠢得代码的啊啊啊啊啊,虽然AC但是太花时间了。
%*c (*代表忽略输入)
string b;
stringstream ss(s);//加<sstream>头文件 将数组按空格分隔输出
int ans=0;
while(ss>>b) {
ans += mp[b];
}
#include <iostream>
#include <cstdio>
#include <map>
#include <sstream>
#include <string>
#include <cstring>
using namespace std;
int MarToEarth(string s)
{
map<string,int>mp;
mp["tret"] = 0;
mp["jan"] = 1;
mp["feb"] = 2;
mp["mar"] = 3;
mp["apr"] = 4;
mp["may"] = 5;
mp["jun"] = 6;
mp["jly"] = 7;
mp["aug"] = 8;
mp["sep"] = 9;
mp["oct"] = 10;
mp["nov"] = 11;
mp["dec"] = 12;
//
mp["tam"] = 1*13;
mp["hel"] = 2*13;
mp["maa"] = 3*13;
mp["huh"] = 4*13;
mp["tou"] = 5*13;
mp["kes"] = 6*13;
mp["hei"] = 7*13;
mp["elo"] = 8*13;
mp["syy"] = 9*13;
mp["lok"] = 10*13;
mp["mer"] = 11*13;
mp["jou"] = 12*13;
string b;
stringstream ss(s);
int ans=0;
while(ss>>b) {
ans += mp[b];
}
printf("%d\n",ans);
}
int getN(string s)
{
map<int,string>mp;
mp[0] ="tret";
mp[1] ="jan";
mp[2] ="feb";
mp[3] ="mar";
mp[4] ="apr";
mp[5] ="may";
mp[6] ="jun";
mp[7] ="jly";
mp[8] ="aug";
mp[9] ="sep";
mp[10] ="oct";
mp[11] ="nov";
mp[12] ="dec";
//
mp[1*13] ="tam" ;
mp[2*13] ="hel" ;
mp[3*13] ="maa" ;
mp[4*13] ="huh" ;
mp[5*13] ="tou" ;
mp[6*13] ="kes" ;
mp[7*13] ="hei" ;
mp[8*13] ="elo" ;
mp[9*13] ="syy" ;
mp[10*13] ="lok" ;
mp[11*13] ="mer" ;
mp[12*13] ="jou" ;
int r = 0,a = 0;
for(int i = 0;i<s.length();i++)
{
char name = s[i];
a = s[i] - '0';
r = r*10 + a;
}
if(r%13==0)
cout<<mp[r/13 * 13]<<endl;
else if(r>13)
cout<<mp[r/13 * 13]<<" "<<mp[r%13]<<endl;
else
cout<<mp[r%13]<<endl;
return r;
}
int main()
{
int n;
scanf("%d%*c",&n);
for(int i =0;i<n;i++)
{
string s1;
getline(cin,s1);
if(s1[0]>='0' && s1[0] <='9')
getN(s1);
else
MarToEarth(s1);
}
return 0;
}