#include <iostream>
#include <sstream>
using namespace std;
const string mars1[14] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
const string mars2[14] = {"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
void toMars ( string s )
{
int n;
stringstream ss(s);
ss >> n;
if ( n <= 12 ) cout << mars1[n];
else {
cout << mars2[n / 13 - 1] << " " << mars1[n % 13];
}
}
void toEarth ( string s )
{
if ( s.length() <= 3 ) {
int flag = 1;
for ( int i = 0; i <= 13; i++ )
if ( mars1[i] == s ) {
cout << i;
flag = 0;
break;
}
if ( flag )
for ( int i = 0; i <= 11; i++ )
if ( mars2[i] == s ) {
cout << i + 13;
break;
}
}
else {
string a, b;
int sum = 0;
for ( int i = 0; i < 3; i++ ) a += s[i];
for ( int i = 4; i <= 6; i++ ) b += s[i];
for ( int i = 0; i <= 11; i++ )
if ( mars2[i] == a ) {
sum += 13 * (i + 1);
break;
}
for ( int i = 0; i <= 13; i++ )
if ( mars1[i] == b ) {
sum += i;
break;
}
cout << sum;
}
}
int main()
{
// freopen("F://input.txt","r",stdin);
int N;
cin >> N;
getchar();
for ( int i = 0; i < N; i++ ) {
string s;
char ch;
while ( ch = getchar() ) {
if ( ch == '\n' ) break;
else s += ch;
}
if ( s[0] >= '0' && s[0] <= '9' ) toMars(s);
else toEarth(s);
cout << endl;
}
return 0;
}
知道了= =,有两个地方错了,一个是13是个特殊值,需要加上一个判断。第二个就是当火星文处于第二个Mars数组中时,应该是(i + 1) * 13;而不是原来的
i + 13.。。
自己还是太菜了
#include <iostream>
#include <sstream>
using namespace std;
const string mars1[14] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
const string mars2[14] = {"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
void toMars ( string s )
{
int n;
stringstream ss(s);
ss >> n;
if ( n <= 12 ) cout << mars1[n];
else {
if ( n % 13 )
cout << mars2[n / 13 - 1] << " " << mars1[n % 13];
else
cout << mars2[n / 13 - 1];
}
}
void toEarth ( string s )
{
if ( s.length() <= 3 ) {
int flag = 1;
for ( int i = 0; i <= 13; i++ )
if ( mars1[i] == s ) {
cout << i;
flag = 0;
break;
}
if ( flag )
for ( int i = 0; i <= 11; i++ )
if ( mars2[i] == s ) {
cout << (i + 1) * 13;
break;
}
}
else {
string a, b;
int sum = 0;
for ( int i = 0; i < 3; i++ ) a += s[i];
for ( int i = 4; i <= 6; i++ ) b += s[i];
for ( int i = 0; i <= 11; i++ )
if ( mars2[i] == a ) {
sum += 13 * (i + 1);
break;
}
for ( int i = 0; i <= 13; i++ )
if ( mars1[i] == b ) {
sum += i;
break;
}
cout << sum;
}
}
int main()
{
// freopen("F://input.txt","r",stdin);
int N;
cin >> N;
getchar();
for ( int i = 0; i < N; i++ ) {
string s;
char ch;
while ( ch = getchar() ) {
if ( ch == '\n' ) break;
else s += ch;
}
if ( s[0] >= '0' && s[0] <= '9' ) toMars(s);
else toEarth(s);
cout << endl;
}
return 0;
}