PAT 1100

题目 : Mars Numbers

分值 : 20
难度 : 中等题
思路 : string 读入然后 转化
坑点 : string 转 int / int转string有点生疏

具体代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
using namespace std;
string A[13] = {"","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string B[13] = {"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int find1(string s)
{
for(int i =1 ; i< 13 ; i++)
{
if(A[i] == s)
return i ;
}
return 0 ;
}
int find2(string s)
{
for(int i =1 ; i< 13 ; i++)
{
if(B[i] == s)
return i ;
}
return 0;
}
int main() {
int N ;
cin >> N ;
getchar() ;
for(int i = 0 ; i< N ; i++)
{
string temp ;
getline(cin , temp) ;
if(isdigit(temp[0]))
{
int num = atoi(temp.c_str()) ;
int l = num %13 ;
int h = num /13 ;
if(l== 0 && h == 0 ) cout <<"tret" <<endl ;
else if (l==0) cout << B[h] <<endl ;
else if( h==0) cout << A[l] <<endl ;
else cout << B[h] <<" "<<A[l] <<endl ;
}
else
{
int end = 0 ;
while (temp[end]!=' ' && end < temp.size()) end ++ ;
int h = 0 , l = 0 ;
if(end == temp.size()) // 只有一个
{
if(find1(temp)) l = find1(temp) ;
else h = find2(temp) ;
}
else{
string t1 = temp.substr(0,end );
string t2 = temp.substr(end+1 );
h = find2(t1) ;
l = find1(t2) ;
}
cout << h*13+l <<endl ;
}

}
}