PAT 乙级 1044

代码

 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
62
63
64
65
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: a2htray
# create date: 2023/3/25

"""
PAT 乙级 1044
"""

mars_digits = [
    'tret',
    'jan', 'feb', 'mar', 'apr',
    'may', 'jun', 'jly', 'aug',
    'sep', 'oct', 'nov', 'dec',
]

mars_carries = [
    'tam', 'hel', 'maa', 'huh',
    'tou', 'kes', 'hei', 'elo',
    'syy', 'lok', 'mer', 'jou',
]


def is_earth(s: str):
    return s.isdigit()


def is_mars(s: str):
    return not is_earth(s)


def to_earth(s: str):
    tokens = s.split(' ')
    if len(tokens) == 1:
        if tokens[0] in mars_digits:
            return mars_digits.index(tokens[0])
        if tokens[0] in mars_carries:
            return (mars_carries.index(tokens[0]) + 1) * 13
    else:
        return (mars_carries.index(tokens[0]) + 1) * 13 + mars_digits.index(tokens[1])


def to_mars(s: str):
    num = int(s)
    if num < 13:
        return mars_digits[num]

    if num % 13 == 0:
        return f'{mars_carries[num // 13 - 1]}'
    else:
        return f'{mars_carries[num // 13 - 1]} {mars_digits[num % 13]}'


if __name__ == '__main__':
    n = int(input())
    lines = []
    for _ in range(n):
        line = input()
        lines.append(line)

    for line in lines:
        if is_earth(line):
            print(to_mars(line))
        else:
            print(to_earth(line))