
Python
Lhw_666
这个作者很懒,什么都没留下…
展开
-
Python|页面置换模拟程序设计
输出结果'''本代码看似很长,但其实主要是因为存储每个算法执行过程导致的,如果只需输出每个算法的缺页率,那么代码行数可以减少一半左右。'''import randomorder_list = [False]*320order_number = int(0)FIFO_list = []FIFO_memory_block = []FIFO_page_fault_rate = 0LRU_list = []LRU_memory_block = []LRU_page_fault_r原创 2020-10-05 20:49:24 · 868 阅读 · 0 评论 -
Python|银行家算法
输入请求资源的进程号以及该进程请求资源数可以实现的操作:检查当前状态是否安全,如果安全则输出安全序列根据输入请求资源的进程号以及该进程请求资源数,判断状态是否安全,如果安全则输出安全序列,否则输出错误下面测试PPT上的四个问题:import numpy''' 参考OS10(死锁).ppt中P22银行家算法示例 设系统中有n个进程,m种资源(本题中有五个进程,3种资源) 可利用资源向量Available:m个元素的数组 最大需求矩阵Max:n×m矩阵原创 2020-10-05 20:48:58 · 1311 阅读 · 0 评论 -
Python|独占设备的分配和回收模拟
结果代码false = 0true = 1n = 4m = 10equip_type_list = []equipment_list = []class Equiptype: def __init__(self, type, count, remain, address): ''' :param type: 设备类名 :param count: 拥有设备台数 :param remain:原创 2020-10-05 20:48:18 · 1117 阅读 · 0 评论 -
Python|模拟文件系统
实验目的:通过一个简单文件系统目录结构的模拟设计,加深了解文件系统的功能和实现实验预备内容复习数据结构中的树型结构。熟悉树节点的插入、删除、修改以及树的遍历方法。实验内容编写一段程序,模拟实现一个简单文件系统的树型目录结构,实现以下命令:命令名 功能 格式create 创建文件 create FileName sizemd 创建目录 md DirectoryNamedelete 删除文件 delete FileNamerd 删除目录 rd DirectoryNamecd 改变文件当前目原创 2020-09-20 17:25:49 · 3350 阅读 · 1 评论 -
Python|进程调度算法
按优先数调度算法实现处理器调度的程序五个进程任意确定一组“优先数”和“要求运行时间”,并输出初始状态实验结果:按时间片轮转发实现处理机调度的程序五个进程任意确定一组“优先数”和“要求运行时间”,并输出初始状态实验结果:import copyimport randomclass PCB: def __init__(self, id, priority, cpu_time, all_time, state): ''' :param id: 进.原创 2020-09-20 17:23:51 · 3649 阅读 · 0 评论 -
Python|分页管理方式下存储分配情况模拟
现有一信息量为5页的作业要装入,运行分配程序,为作业分配主存且建立页面,之后运行回收程序。过程中打印分配与回收前后位示图和空闲块数有一作业执行结束,它占用的块号为第4,5,6,31块,运行回收程序,回收作业,归还主存块。打印回收前后位示图和空闲块数。当装入一个作业时,当前空闲块数不能满足作业需求则分配失败import numpyfrom collections import Countermain_memory = numpy.asarray([ [1, 1, 0, 0, 1,.原创 2020-09-20 17:21:52 · 1032 阅读 · 0 评论 -
Python|Windows下实现经典进程同步问题——理发师问题
采用python多线程模拟理发师问题,初始的时候需要设置理发店可供等待顾客坐的椅子数。理发师问题用P、V操作描述如下:信号量mutex表示waiting的互斥操作权,初值为1信号量bchair表示理发椅互斥,初值为1信号量wchair表示等待椅资源,初值为n信号量ready和finish进行理发师和顾客间通信,初值为0int waiting = 0;//顾客数(正在理发的+等待的,最多N+1人)semphore mutex = 1, bchair = 1, wchair = n, ready原创 2020-09-20 17:19:16 · 1423 阅读 · 0 评论 -
Python|模拟实现动态分区存储管理
程序设计前分析:初步想法:最优适应算法只是在执行首次适应算法之前,对空闲区表按为空闲空间长度升序排序,之后只要执行最先适应算法即可。通过程序实现初步想法之后发现:在执行最优适应算法之后,由于会对空闲区进行合并,但是我的空闲区合并函数是在空闲区表按空闲空间起址升序排序的基础上进行合并的。而执行最优适应算法之前会会打乱这种排序,因此在执行空闲区合并函数的时候,应该在开头对空闲区表按空闲空间起址升序排序,这样才能得到正确的合并。执行空闲区合并函数后,要对空闲区表重新按照空闲空间长度升序排序,以显示正确的空原创 2020-09-20 17:16:32 · 2560 阅读 · 2 评论 -
Py||study_1
BIF(内置函数)help()这个BIF用于显示BIF的功能描述5+8=13(数字相加)‘5’+‘8’=‘58’(字符串拼接)单引号和双引号的作用相同但必须成对出现当字符串中需要出现单引号或双引号时,使用转义符号(\)对字符串中的引号进行转义示例:‘Let’s go’(将单引号替换为双引号,此时双引号内的单引号可正常输出)当转义符号(\)与字母n在一起出现的时候,可使用原始字符串(只...原创 2019-11-23 21:29:42 · 198 阅读 · 0 评论 -
Py||study_3(字符串&序列)
字符串也可用列表和元组中学到的分片,在Python中没有字符只有字符串,字符就是长度为1的字符串str.casefold()将字符串的所有字符变为小写str.count( , , ) 三个参数依次是要查找的子字符串,检索的起始位置和终止位置,用于查找子字符串在所选范围内出现的次数str.find( , , )str.index( , , )三个参数依次是要找的子字符串,检索的起始位置...原创 2019-11-23 21:29:34 · 222 阅读 · 0 评论 -
Py||Long integer subtraction
题目描述Calculate and output the difference between two long integers (not less than 0, not greater than 10 to the power of 100) to ensure that the result is non-negative.输入The input is a set of long i...原创 2019-10-26 11:29:03 · 253 阅读 · 0 评论 -
Py||Large integer multiplication
题目描述A large integer is an integer that far exceeds the range of integer types represented by the Python language, such as 10 to the power of 100. Please calculate the multiply result of two large in...原创 2019-10-26 11:28:00 · 312 阅读 · 0 评论 -
Py||Who is the turn ?
题目描述Ping Pang is very popular in China. Assuming that A and B are playing table tennis, each time A is the first serve the Ping Pang ball, then the rules for serving the ball are as follows:One pla...原创 2019-10-26 11:27:18 · 267 阅读 · 0 评论 -
Py||Division
题目描述Complete the division operation, input as multiple lines of data, each line consists of two integers a and b, separated by a space.For each row of data, output the result of a÷b, the result is r...原创 2019-10-26 11:26:37 · 180 阅读 · 0 评论 -
Py||Basketball game
题目描述The NBA has a comprehensive judgment index for the player’s technical statistics - the efficiency value, which is calculated as:efficiency value = [(score + rebound + assists + steal + block) - ...原创 2019-10-26 11:25:56 · 241 阅读 · 0 评论 -
Py||Palindrome
题目描述A string, if the same for both read and reverse read, is called a palindrome. Please write a program to determine if the input string is a palindrome.输入Enter the number of the string n, 0 < ...原创 2019-10-26 11:25:16 · 204 阅读 · 0 评论 -
Py||Judge triangle
题目描述Write a program to determine if the given three edges can form a triangle.The types of triangles include: equilateral triangles, isosceles triangles, right triangles, regular trianglesIt is als...原创 2019-10-26 11:24:22 · 291 阅读 · 0 评论 -
Py||Separate
题目描述Calculate the sum of two integers.输入Input contains multi-lines, each line separated with a dot.输出For each line of input, output the sum of two integers and wrap.样例输入 Copy1,12,2样例输出 Copy2...原创 2019-10-26 11:23:43 · 446 阅读 · 0 评论 -
Py||Full Permutation
题目描述Write a program to list all the permutations that can be formed by N integers from 1 to N, and output them in lexicographic order.For example, given an integer N = 2,the permutations are:1 22...原创 2019-10-25 11:00:07 · 189 阅读 · 0 评论 -
Py||Count down
题目描述Mike is a clever boy. Today, Mike’s teacher gave him an assignment:The teacher gave Mike a few cards, each card has two numbers, then the teacher asked Mike to look at the card, and asked him lo...原创 2019-10-25 10:59:22 · 219 阅读 · 0 评论 -
Py||factorial 0s number
题目描述Given a non-negative integer N, the factorial of N is N!, now you should calculate the number of 0 at the end of N!.For example, N=10, N! =3628800, then the number of 0 at the end of N! is 2.输入...原创 2019-10-25 10:58:41 · 203 阅读 · 0 评论 -
Py||Minimum currency payment problem
题目描述The current monetary system is (1, 2, 5, 10, 20, 50, 100).Please design an algorithm that given a number A, calculate the amount of each currency required to pay with the minimum number of curre...原创 2019-10-25 10:57:58 · 175 阅读 · 0 评论 -
Py||Real Small Water Problem
题目描述The senior wanted you to create a water problem.This made you a headache.So you asked BingYu for help.Immediately after he listened,he came up with a problem:Give you a positive integer n.Funct...原创 2019-10-25 10:57:16 · 809 阅读 · 0 评论 -
Py|| Friendly number
题目描述There are two integers a snd b. If the sum of b’s divisors equals to a, and the sum of a’s divisors equals to b, we call these two integers are “Friendly numbers”.E.g:9 and 4The sum of 9’s d...原创 2019-10-25 10:56:35 · 242 阅读 · 0 评论 -
Py||Big Dipper
题目描述The Big Dipper number is a 7-digit number, which equals to the sum of every digit’s 7 powers.For example:1741725 is a Big Dipper number because of:17+77+47+17+77+27+5^7=1741725Please write a ...原创 2019-10-25 10:56:01 · 259 阅读 · 0 评论 -
Py||Daffodil
题目描述A “daffodil” number is a 3-digits number and it equals to the sum of every digit’s 3 powers.For example, 153 is a “daffodil” number, because 153=13+53+33Write a program for determining if a g...原创 2019-10-25 10:55:12 · 319 阅读 · 0 评论 -
Py||Insert
题目描述There is already an array(A) of 9 elements that have been arranged.Entering a new number, you should insert the new number into A according to the original ordering rules.Write a program to imp...原创 2019-10-25 10:54:31 · 194 阅读 · 0 评论 -
Py||Monkey
题目描述A monkey picked up a few peaches on the first day and immediately ate half of it. It was not enough, and it ate one more.The next morning, the remaining peaches were eaten in half and one more....原创 2019-10-25 10:53:48 · 236 阅读 · 0 评论 -
Py||一键排序
s=[int(i) for i in input().split()]s.sort()print(*s)原创 2019-10-16 22:54:32 · 184 阅读 · 0 评论 -
Py||用回车空行分开每组数据
题目描述整型A,B范围0<A<1e2000<B<1e200计算A+B输入:第一行一个整型变量T(1<T<30)表示测试样例的组数紧接着的2*T行表示A和B(以回车间隔)样例输入 Copy2123456345111样例输出 Copy579456把回车当成输入字符串,最后一组数据不用输入回车n=int(input())for i...原创 2019-10-15 22:05:06 · 344 阅读 · 0 评论 -
Py||乘积尾零
题目描述共有10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零输入输入为100个数字输出输出末尾有多少个0m=[]s=int(1)for k in range(10): a,b,c,d,e,f,g,h,i,j=map(int,input().split()) s=s*a*b*c*d*e*f*g*h*i*jn=0s1=[str(s)]s2=[]f...原创 2019-10-15 21:59:58 · 196 阅读 · 0 评论 -
Py||除法训练(保留小数点后指定位数不足补零)
题目描述对三个整数a,b,c,求a÷b的值,结果保留c位有效数字,c>=0 且 c<=1000输入输入包括多行数据,每行是用空格分隔的三个整数a b c,其中c>=0 且 c<=1000。输出对输入的每行数据,输出包括一行,a÷b的保留c位有效数字的结果,如果b等于0,该行输出error样例输入 Copy1 2 11 2 00 2 2样例输出 Copy...原创 2019-10-15 21:28:54 · 2649 阅读 · 0 评论 -
Py||删除重复元素并按原顺序输出
while True: ss=input() list1=list(set(ss)) list1.sort(key=ss.index) for i in list1: print(i,end='') print()原创 2019-10-15 11:26:55 · 364 阅读 · 0 评论 -
Py||回文字符串
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.Find the largest palindrome made from the product of two 3-digit n...原创 2019-10-14 22:52:00 · 200 阅读 · 0 评论 -
Py||输出重复字母最多的第一个单词
Using the Python language, have the functionletterCount(words : str) -> strtake the words parameter being passed and return the first word with the greatest number of repeated letters.Examples:...原创 2019-10-14 22:49:15 · 533 阅读 · 0 评论 -
Py||把列表中的一个元素分成多个元素
a=[int(i) for i in input().split()]b=[]b.extend(str(a[0]))for i in b: print(int(i)+1)原创 2019-10-14 22:32:55 · 1064 阅读 · 0 评论 -
Py||输出列表中的每个元素
a=[int(i) for i in input().split()]print(*a)原创 2019-10-14 21:01:45 · 1627 阅读 · 0 评论 -
Py||有序单链表删除重复元素
题目描述根据一个递增的整数序列构造有序单链表,删除其中的重复元素输入输入包括多组测试数据,每组测试数据占一行,第一个为大于等于0的整数n,表示该单链表的长度,后面跟着n个整数,表示链表的每一个元素。整数之间用空格隔开;n小于十万。输出针对每组测试数据,输出包括两行,分别是删除前和删除后的链表元素,用空格隔开如果链表为空,则只输出一行,list is empty样例输入 Copy5 ...原创 2019-10-14 00:07:50 · 249 阅读 · 0 评论 -
Py||单链表反转
题目描述根据一个整数序列构造一个单链表,然后将其反转。例如:原单链表为 2 3 4 5 ,反转之后为5 4 3 2输入输入包括多组测试数据,每组测试数据占一行,第一个为大于等于0的整数n,表示该单链表的长度,后面跟着n个整数,表示链表的每一个元素。整数之间用空格隔开输出针对每组测试数据,输出包括两行,分别是反转前和反转后的链表元素,用空格隔开如果链表为空,则只输出一行,list is...原创 2019-10-13 23:55:09 · 167 阅读 · 0 评论 -
DS||有序归并
题目描述 将两个升序序列合并。输入 第 1 行为测试用例个数 m。 第 2 行开始为 m 个测试用例。 每个测试用例由两行空格隔开的整数组成,每一行整数的第一个整数 n(1 ≤ n ≤ 100)为升序序列的长度,后面是 n 个升序排列的整数。输出 对每个测试用例,输出一行归并后的非递减序列,每个整数之间用一个空格隔开。样例输入 Copy15 1 3 5 7 93 2...原创 2019-10-13 22:32:29 · 199 阅读 · 0 评论