摘要: def fn(a, n): total = 0 current = 0 for _ in range(n): current = current * 10 + a # 构造当前项:2 → 22 → 222... total += current # 累加当前项到总和 return total imp 阅读全文
posted @ 2026-06-19 20:50 Cx330。 阅读(8) 评论(0) 推荐(0)
摘要: 读取输入 s = input().strip() 固定汇率:1美元 = 6人民币 rate = 6 判断币种并计算 if s[0] == 'R': # 人民币转美元:金额 / 汇率 cny = float(s[1:]) usd = cny / rate print(f"${usd:.2f}") el 阅读全文
posted @ 2026-06-19 20:50 Cx330。 阅读(3) 评论(0) 推荐(0)
摘要: import math 平面点类 Point class Point: # 构造函数:初始化x, y坐标 def init(self, x=0, y=0): self.x = x # 横坐标 self.y = y # 纵坐标 计算到原点(0,0)的距离 def distance(self): # 距 阅读全文
posted @ 2026-06-19 20:49 Cx330。 阅读(2) 评论(0) 推荐(0)
摘要: def lru_page_faults(n, pages): """ 模拟LRU页面置换算法,计算缺页次数 :param n: 主存块数量 :param pages: 页面访问序列(列表) :return: 缺页次数 """ memory = [] # 模拟主存块,保存当前驻留的页面 page_fa 阅读全文
posted @ 2026-06-19 20:46 Cx330。 阅读(8) 评论(0) 推荐(0)
摘要: def print_pascal_triangle(n): """ 输出n行杨辉三角形,每个数占5位右对齐 :param n: 要输出的行数(n>0) """ # 初始化杨辉三角,第1行只有1个元素:[1] triangle = [] for i in range(n): # 第i行有i+1个元素, 阅读全文
posted @ 2026-06-19 20:46 Cx330。 阅读(3) 评论(0) 推荐(0)
摘要: def sieve_of_eratosthenes(n): """ 埃拉托斯特尼筛法,求[2, n]范围内的所有素数 :param n: 筛法的上界 :return: 布尔数组,is_prime[i]为True表示i是素数 """ # 初始化:假设所有数都是素数 is_prime = [True] 阅读全文
posted @ 2026-06-19 20:46 Cx330。 阅读(8) 评论(0) 推荐(0)
摘要: def find_saddle_points(matrix): """ 查找5x5矩阵中的所有鞍点 鞍点定义:所在行的最大值,且所在列的最小值 :param matrix: 5x5的二维列表 :return: 鞍点列表,每个元素为 (行坐标, 列坐标, 值),坐标从1开始 """ saddle_po 阅读全文
posted @ 2026-06-19 20:46 Cx330。 阅读(5) 评论(0) 推荐(0)
摘要: def funcos(eps, x): # 初始化:第0项为 x^0 / 0! = 1 sum_cos = 1.0 term = 1.0 k = 0 # 循环计算,直到当前项的绝对值小于eps while abs(term) >= eps: k += 1 # 递推计算下一项:term_{k} = t 阅读全文
posted @ 2026-06-19 20:45 Cx330。 阅读(2) 评论(0) 推荐(0)
摘要: include <stdio.h> include <stdlib.h> void WriteLetter(FILE *f, int n) { // 定义一个字符变量用于存储大写字母 char ch = 'A'; // 循环写入前n个大写字母 for (int i = 0; i < n; i++) 阅读全文
posted @ 2026-06-19 20:45 Cx330。 阅读(3) 评论(0) 推荐(0)
摘要: import itertools def main(): # 1. 读取输入 # 第一行:n 和 m n, m = map(int, input().split()) # 第二行:n 个字母 letters = input().split() 2. 输出排列(Permutation) print(" 阅读全文
posted @ 2026-06-19 20:45 Cx330。 阅读(10) 评论(0) 推荐(0)