快乐冲浪与生活

多体验、多体会、多体悟

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

"""
PAT 乙级 1018
"""

if __name__ == '__main__':
    n = int(input())
    first = [0, 0, 0]
    second = [0, 0, 0]
    first_win = 0
    second_win = 0

    alphabet = ['B', 'C', 'J']

    for _ in range(n):
        p1, p2 = input().split()
        if p1 == 'C' and p2 == 'J':
            first[1] += 1
            first_win += 1
        elif p1 == 'C' and p2 == 'B':
            second[0] += 1
            second_win += 1
        elif p1 == 'B' and p2 == 'J':
            second[2] += 1
            second_win += 1
        elif p1 == 'B' and p2 == 'C':
            first[0] += 1
            first_win += 1
        elif p1 == 'J' and p2 == 'B':
            first[2] += 1
            first_win += 1
        elif p1 == 'J' and p2 == 'C':
            second[1] += 1
            second_win += 1

    print(first_win, n - first_win - second_win, second_win)
    print(second_win, n - first_win - second_win, first_win)

    print(alphabet[first.index(max(first))], alphabet[second.index(max(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
27
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: a2htray
# create date: 2023/3/8

"""
PAT 乙级 1022
"""


if __name__ == '__main__':
    num1, num2, base = map(int, input().split(' '))

    total = num1 + num2
    if total == 0:
        print(0)
        exit(0)

    res = []
    while total >= 1:
        res = [total % base] + res
        total = total // base

    if res[0] == 0:
        res = res[1:]

    print(''.join(map(str, res)))

代码

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

"""
PAT 乙级 1013
"""
import math


def is_prime(num):
    for i in range(2, int(math.sqrt(num)) + 1):
        if num % i == 0:
            return False
    return True


if __name__ == '__main__':
    nums_str = input().split(' ')
    m, n = int(nums_str[0]), int(nums_str[1])
    prime_nums = [0] * n

    i = 0
    num = 2
    while i != n:
        if is_prime(num):
            prime_nums[i] = num
            i += 1
        num += 1

    output_nums = prime_nums[m - 1:n]
    for i in range(0, len(output_nums), 10):
        print(' '.join([str(v) for v in output_nums[i:i + 10]]))

代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: a2htray
# create date: 2023/3/3

"""
PAT 乙级 1009
"""

if __name__ == '__main__':
    statement = input().split(' ')
    statement.reverse()
    print(' '.join(statement))

代码

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

"""
PAT 乙级 1007
"""
import math


def is_prime(n):
    prime = True
    for i in range(3, int(math.sqrt(n)) + 1):
        if n % i == 0:
            prime = False
            break
    return prime


if __name__ == '__main__':
    nums = [n for n in range(3, int(input()) + 1)]
    nums = [n for n in nums if n % 2 != 0]

    nums = list(filter(is_prime, nums))
    if len(nums) <= 1:
        print(0)
        exit(0)

    count = 0
    i = 0
    j = 1
    while j != len(nums):
        if nums[j] - nums[i] == 2:
            count += 1
        i += 1
        j += 1

    print(count)

代码

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

"""
PAT 乙级 1006
"""

if __name__ == '__main__':
    chars = [*input()]
    chars.reverse()

    tail = []
    for i in range(1, int(chars[0]) + 1):
        tail.append(str(i))

    bs_list = [[], []]
    for i, char in enumerate(chars[1:]):
        if i == 0:
            bs_list[0] = ['S'] * int(char)
        else:
            bs_list[1] = ['B'] * int(char)

    print(''.join(bs_list[1] + bs_list[0] + tail))

代码

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

"""
PAT 乙级 1005
"""


def compute_sequence(num):
    sequence = []
    while num != 1:
        if num % 2 == 0:
            num = num // 2
        else:
            num = (num * 3 + 1) // 2
        sequence.append(num)

    return sequence


if __name__ == '__main__':
    sequences = []
    n = int(input())
    nums = [int(num) for num in input().split(' ')]
    i = 0
    while i < n:
        sequence = compute_sequence(nums[i])
        sequences.append(sequence[:-1])
        i += 1

    key_nums = []
    for i, num in enumerate(nums):
        is_key = True
        for j, sequence in enumerate(sequences):
            if i == j:
                continue
            if num in sequence:
                is_key = False
                break

        if is_key:
            key_nums.append(num)

    key_nums.sort(reverse=True)
    print(' '.join([str(num) for num in key_nums]))

代码

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

"""
PAT 乙级 1004
"""


def get_score(student):
    return student[2]


if __name__ == '__main__':
    n = int(input())

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

    students.sort(key=get_score)

    print(students[len(students) - 1][0], students[len(students) - 1][1])
    print(students[0][0], students[0][1])

代码

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

"""
PAT 乙级 1016
"""


def count(string, char):
    c = 0
    for v in string:
        if v == char:
            c += 1
    return c


def pad(char, num):
    if num == 0:
        return '0'
    ret = ''
    while num != 0:
        ret += char
        num -= 1
    return ret


if __name__ == '__main__':
    strings = input().split(' ')
    a_count = count(strings[0], strings[1])
    b_count = count(strings[2], strings[3])

    print(int(pad(strings[1], a_count)) + int(pad(strings[3], b_count)))