代码 #!/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':...
代码 # 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('...
代码 # basic_1001.py if __name__ == '__main__': n = int(input()) step = 0 while n != 1: if n % 2 == 0: n = n // 2 else: n = (3 * n + 1) // 2 step += 1 print(step) 运行 input: 100 output: 18
PAT 甲级 1003 。 # -*- coding:utf-8 -*- if __name__ == '__main__': # n 树中节点个数 # m 非叶子节点个数 n, m = list(map(int, input().strip().split(' '))) # 二维数组 # 元素的下标表示节点的 ID # 第 1 个元素不使用 tree = [[] for _ in range(n+1)] while m != 0: tokens = list(map(int, input().split(' '))) _id = tokens[0] children = tokens[2:] tree[_id] =...
PAT 甲级 1003 。 # -*- coding:utf-8 -*- import sys MAX_INT = sys.maxsize if __name__ == '__main__': # m 城市个数 # n 路径条数 # start 起始城市下标 # end 结束城市下标 m, n, start, end = map(int, input().strip().split(' ')) # nums_of_teams 各城市救援队的数量 nums_of_teams = list(map(int, input().strip().split(' '))) assert m == len(nums_of_teams) # 城市间...