快乐冲浪与生活

多体验、多体会、多体悟

0%

代码

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

"""
PAT 乙级 1015
"""
from functools import cmp_to_key


def sort_students(student1, student2):
    total1 = sum(student1[1:])
    total2 = sum(student2[1:])
    if total1 != total2:
        return -1 if total1 > total2 else 1
    elif student1[1] != student2[1]:
        return -1 if student1[1] > student2[1] else 1
    else:
        return -1 if int(student1[0]) > int(student2[1]) else 1


if __name__ == '__main__':
    [n, base_score, priority_score] = list(map(int, input().split()))

    students = []
    while n != 0:
        tokens = input().split()
        students.append((tokens[0], int(tokens[1]), int(tokens[2])))
        n -= 1

    student_group = [[], [], [], []]

    for i, student in enumerate(students):
        # 德分和才分均低于最低分数线
        if student[1] < base_score or student[2] < base_score:
            continue

        # 德分和才分均大于等于优化分数线
        if student[1] >= priority_score and student[2] >= priority_score:
            student_group[0].append(student)
        elif student[1] >= priority_score > student[2]:
            student_group[1].append(student)
        elif student[1] < priority_score and student[2] < priority_score:
            if student[1] >= student[2]:
                student_group[2].append(student)
            else:
                student_group[3].append(student)
        else:
            student_group[3].append(student)

    m = sum([len(g) for g in student_group])
    print(m)

    student_group[0].sort(key=cmp_to_key(sort_students))
    student_group[1].sort(key=cmp_to_key(sort_students))
    student_group[2].sort(key=cmp_to_key(sort_students))
    student_group[3].sort(key=cmp_to_key(sort_students))

    students = student_group[0] + student_group[1] + student_group[2] + student_group[3]
    for student in students:
        print('%s %d %d' % (student[0], student[1], student[2]))

代码

 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
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: a2htray
# create date: 2023/3/4

"""
PAT 乙级 1014
"""

week_dict = {
    'A': 'MON',
    'B': 'TUE',
    'C': 'WED',
    'D': 'THU',
    'E': 'FRI',
    'F': 'SAT',
    'G': 'SUN',
}

hour_dict = {
    '0': '00',
    '1': '01',
    '2': '02',
    '3': '03',
    '4': '04',
    '5': '05',
    '6': '06',
    '7': '07',
    '8': '08',
    '9': '09',
    'A': '10',
    'B': '11',
    'C': '12',
    'D': '13',
    'E': '14',
    'F': '15',
    'G': '16',
    'H': '17',
    'I': '18',
    'J': '19',
    'K': '20',
    'L': '21',
    'M': '22',
    'N': '23',
}

if __name__ == '__main__':
    n_line = 4
    lines = []
    while n_line != 0:
        lines.append(input())
        n_line -= 1

    week, hour, second = '', '', ''

    j = 0
    for i, char in enumerate(lines[0]):
        if char == lines[1][i] and char in week_dict.keys():
            j = i
            week = week_dict[char]
            break

    for i in range(j+1, len(lines[0])):
        if lines[0][i] == lines[1][i] and lines[0][i] in hour_dict.keys():
            hour = hour_dict[lines[0][i]]
            break

    for i, char in enumerate(lines[2]):
        if char.isalpha() and char == lines[3][i]:
            second = '%.2d' % i
            break

    print(week + ' ' + hour + ':' + second)

代码

 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
# basic_1002.py
chinese_pinyins = [
    'ling',
    'yi',
    'er',
    'san',
    'si',
    'wu',
    'liu',
    'qi',
    'ba',
    'jiu',
]

if __name__ == '__main__':
    num_chars = input()

    total = 0
    for num_char in num_chars:
        total += int(num_char)

    output = []
    for num_char in str(total):
        output.append(chinese_pinyins[int(num_char)])

    print(' '.join(output))

运行

1
2
3
4
input:
1928374
output:
san si