58集团23校招测试工程师卷

编程题-操作系统先入先出算法实现

#
import sys

# 从输入中获取数据
nums = list(map(int, input().split(',')))

# 获取缓存大小和页面列表
num_len = nums[0]
mylist = nums[1:]

# 初始化缓存
cache = []

# 处理页面置换逻辑
for value in mylist:
    if value in cache:
        continue
    if len(cache) >= num_len:
        cache.pop(0)  # 移除最早进入的页面
    cache.append(value)

# 输出最终缓存中的页面
print(cache)

Top5热词问题

def top5_search_terms(input_string):
    # 解析输入字符串
    terms = input_string.split(',')
    search_dict = {}
    
    # 构建搜索词字典
    for term in terms:
        search_term, count = term.split(':')
        search_dict[search_term] = int(count)
    
    # 按搜索次数排序并取前5项
    sorted_terms = sorted(search_dict.items(), key=lambda x: x[1], reverse=True)
    top5_terms = sorted_terms[:5]
    
    # 打印结果
    for term, count in top5_terms:
        print(f"{term}:{count}")

# 示例输入
input_string=input()

# 调用函数并打印结果
top5_search_terms(input_string)

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值