原题传送门 1. 题目描述 2. Solution import sys if sys.platform != "linux": sys.stdin = open("input/HJ94.txt") def solve(names, tickets): result = {name: 0 for name in names} result["Invalid"] = 0 for c in tickets:
原题传送门 1. 问题描述 2. Solution import sys from datetime import datetime if sys.platform != "linux": sys.stdin = open("input/HJ74.txt") def solve(s): start = 0 end = start + 1 res = [] while start < len(s) and end
原题传送门 1. 题目描述 2. Solution import sys from datetime import datetime if sys.platform != "linux": sys.stdin = open("input/HJ73.txt") def solve(s): end = datetime.strptime(s, "%Y %m %d") start = datetime.strptime(
原题传送门 1. 问题描述 2. Solution 1、思路分析 令target=n * n * n,res保存n个奇数,初始时res=[1],若len(res) < n,则直接添加下一个奇数(res[-1]+2),若sum(res) < target,则去掉res[0],添加下一个奇数(res[-1]+2)。 2、代码实现 import sys if sys.platform != "linux": file_i
原题传送门 1. 问题描述 2. Solution 1、思路分析 用数组充当自定义哈希表来统计字符串中字符出现次数,若存在一个字符在短字符串中出现过,而未在长字符串中出现则返回False。 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ81.txt") def
import sys#带入系统from PyQt5.QtWidgets import *class quitapp(QMainWindow): def __init__(self,parent=None): super(quitapp,self).__init__(parent) #初始化 self.setWindowTitle('退出程序') self.resize(600,600) #获取创建一个Bu
案例说明: KingbaseES V8R6C5版本中使用了securecmdd工具,用于主机节点间的通讯,默认端口8890。备份工具sys_backup.sh默认使用了securecmdd工具,对于通用机单实例环境,在执行“sys_backup.sh init”后,会调用securecmd工具连接主机节点备份,导致在执行“sys_backup.sh start”启动备
原题传送门 1. 问题描述 2. Solution 1、思路 本题是找规律的题,只要往下再写就行就可以看出奇偶规律: n result 1 -1 2 -1 3 2 4 3 5 2 6 4 7 2 8 3 9 2 10 4 11 2 2、实现 import sys if sys.platform != "linux": file_in = open("input/H
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 简单处理直接使用 eval把字符串表达式直接求值。 用栈计算方式参考: HJ50 四则运算。 2、代码实现 import sys for line in sys.stdin: s = line.strip() print(int(eval(s)))
原题传送门 1. 题目描述 2. Solution import sys if sys.platform != "linux": file_in = open("input/HJ55.txt") sys.stdin = file_in for line in sys.stdin: n = int(line.strip()) cnt = 0 for i in range(1, n + 1): if i %
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 把字符串从后往前遍历,求和,保存和的个位到结果,进位进入下一位求和,逆序输出结果。 2、代码实现 import sys if sys.platform != "linux": file_in = open("input/HJ57.txt") sys.stdin = file_in while True: try:
原题传送门 1. 问题描述 2. Solution 1、思路分析 遍历,求所有的真因子,对所有真因子求和。 2、代码实现 import sys if sys.platform != "linux": file_in = open("input/HJ56.txt") sys.stdin = file_in def is_perfect_number(n): factors = [1] i = 2 w
原题传送门 1. 问题描述 2. Solution 遍历2次,第1次计数,第2次找出第1次 import sys if sys.platform != "linux": file_in = open("input/HJ59.txt") sys.stdin = file_in def solve(s): from collections import Counter cnt = dict(Counter(s)) for
原题传送门 1. 问题描述 2. Solution 1、思路分析 堆或优先队列。 2、代码实现 import heapq import sys if sys.platform != "linux": sys.stdin = open("input/HJ58.txt") def solve(n, k, nums): nums.sort() [print(x, end=" ") for x in nums[:k]]
原题传送门 1. 问题描述 2. Solution 1、思路 从中间n//2向两侧遍历,找到第一组素数和即可。 2、实现 import sys if sys.platform != "linux": file_in = open("input/HJ60.txt") sys.stdin = file_in def is_prime(n): i = 2 while i * i <= n: if n
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 最朴素的想法直接转换成二进制字符串,统计1的个数。 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ15.txt") def solve(n): n_bin = bin(n).replace("0b", "") print(n_bi
原题传送门 1. 问题描述 2. Solution 滑动窗口 import sys if sys.platform != "linux": file_in = open("input/HJ64.txt") sys.stdin = file_in def solve(n, s): cur = 1 start = 1 for c in s: if c == 'U':
原题传送门 1. 问题描述 2. Solution import sys if sys.platform != "linux": file_in = open("input/HJ67.txt") sys.stdin = file_in def solve(nums, target): if len(nums) == 1: return nums[0] == target else: for i
原题传送门 1. 题目描述 2. Solution import sys if sys.platform != "linux": file_in = open("input/HJ68.txt") sys.stdin = file_in def solve(): n = int(input().strip()) order = input().strip() # 0代表从高到低,1代表从低到高 reverse =
原题传送门 1. 问题描述 2. Solution 参考LeetCode5 Longest Palindromic Substring import sys if sys.platform != "linux": file_in = open("input/HJ32.txt") sys.stdin = file_in def solve(s): n = len(s) dp = [[False] * n for _ in ra
原题传送门 1. 问题描述 2. Solution 1、思路 bit对齐 2、实现 import sys if sys.platform != "linux": file_in = open("input/HJ33.txt") sys.stdin = file_in def int2bin(n, bits=8): n_b = bin(n).replace("0b", "") return
原题传送门 1. 问题描述 2. Solution 1、思路分析 按ASCII码排序 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ34.txt") for line in sys.stdin: s = line.strip() sorted_s = sorted(s, key=lambda x: ord(x)) print(&qu
原题传送门 1. 问题描述 2. Solution 1、思路分析 找规律 0 | 1 3 6 10 1 | 2 5 9 2 | 4 8 3 | 7 0 1 0 2 1 0 3 2、代码实现 import sys if sys.platform != "linux": file_in = open("input/HJ35.txt") sys.stdin = file_in """ 0 | 1 3 6 10 1 | 2
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 先生成密钥,对输入的key按输入序去重(即保留第1次出现的字符)保存结果到letters2,然后遍历a~z,把未出现在letters2中的字符加入到letters2。 之后就是加密过程,按照下标取出对应字符即可。 2、代码实现 import sys if sys.platfor
原题传送门 1. 题目描述 2. Solution 1、思路分析 斐波那契数列 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ37.txt") # 迭代实现 def solve(n): a, b = 0, 1 for i in range(n): a, b = b, a + b print(a) de