代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/6 """ PAT 乙级 1020 """ from functools import cmp_to_key class MoonCake: def __init__(self, num, total_price): self.num = num self.total_price = total_price self.unit_price = 1.0 * self.total_price / self.num def cmp(mooncake1,...
代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/6 """ PAT 乙级 1019 """ def get_sorted_nums(num_str): dn = 4 - len(num_str) for _ in range(dn): num_str = '0' + num_str nums = list(map(int, num_str)) nums.sort() return 1 * nums[0] + 10 * nums[1] + 100 * nums[2] + 1000 * nums[3], \...
代码 #!/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':...
代码 #!/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...
代码 #!/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]),...
代码 #!/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))
代码 #!/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)]...
代码 #!/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]...
代码 #!/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 =...
代码 #!/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...