蓝桥杯备赛指南
大学C组
枚举
from enum import Enum
class Weekday(Enum):
monday = 1
tuesday = 2
wednesday = 3
thirsday = 4
friday = 5
saturday = 6
sunday = 7
print(Weekday.wednesday) # Weekday.wednesday
print(type(Weekday.wednesday)) # <enum 'Weekday'>
print(Weekday.wednesday.name) # wednesday
print(Weekday.wednesday.value) # 3
排序
冒泡排序
def bubble_sort_with_flag(nums:list[int]) -> list[int]:
n = len(nums)
for i in range(n-1, 0, -1):
flag = False
for j in range(0, i):
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nusm[j+1], nums[j]
flags = True
if not flag:
break
return nums
选择排序
def selection_sort(nums:list[int]) -> list[int]:
n = len(nums)
for i in range(n):
k = i
for j in range(i+1, n):
if nums[k] > nums[j]:
k = j
nums[i], nums[k] = nums[k], nums[i]
return nums
插入排序
def insertion_sort(nums:list[int]) -> list[int]:
n = len(nums)
for i in range(1, n):
base = nums[i]
j = i-1
while j >= 0 and nums[j] > base:
nums[j+1] = nums[j]
j -= 1
nums[j] = nums[base]
return nums
搜索
BFS
标签:指南,杯备赛,nums,int,list,wednesday,蓝桥,range,Weekday
From: https://www.cnblogs.com/LPF05/p/18110360/LPF-lanqiao-competition-learning1