代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/13 """ PAT 乙级 1033 """ if __name__ == '__main__': bad_keys = input() shift_bad = '+' in bad_keys for v in input(): if v in bad_keys or v.upper() in bad_keys: continue if shift_bad and ord('A') <= ord(v) <= ord('Z'): continue...

代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/12 """ PAT 乙级 1031 """ weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] m = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'] def weight_sum(digits): total = 0 for i, digit in enumerate(digits): total += digit...

代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/12 """ PAT 乙级 1029 """ if __name__ == '__main__': statement1 = input() statement2 = input() got_dict = {} statement1 = statement1.upper() statement2 = statement2.upper() for c in statement1: if c not in got_dict: if c not in...

代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/9 """ PAT 乙级 1026 """ if __name__ == '__main__': start_clock, end_clock = map(int, input().split(' ')) duration = 1.0 * (end_clock - start_clock) / 100 h = int(duration // 3600) m = int(duration % 3600 // 60) s = str(duration %...

代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/8 """ PAT 乙级 1024 """ from typing import List class SciNumber: def __init__(self, s: str): self.sign = '-' if s[0] == '-' else '' nums, exp = s[1:].split('E') self.nums = [v for v in nums] self.left_move = exp[0] == '-' self.exp =...

代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/8 """ PAT 乙级 1023 """ if __name__ == '__main__': digits = [] for i, digit in enumerate(map(int, input().split(' '))): digits += [i] * digit digits.sort() if digits[0] != 0: print(''.join(map(str, digits))) exit(0) for i, v in...

代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/7 """ PAT 乙级 1021 """ if __name__ == '__main__': counts = [0] * 10 for s in input(): counts[int(s)] += 1 for i, count in enumerate(counts): if count != 0: print('%d:%d' % (i, count))

代码 #!/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':...