Python容器练习

n = int(input())   
scores = list(map(int, input().split())) 
best = max(scores)   
for i in range(n):
    grade = 'F'   
    if scores[i] >= best - 10:
        grade = 'A'
    elif scores[i] >= best - 20:
        grade = 'B'
    elif scores[i] >= best - 30:
        grade = 'C'
    elif scores[i] >= best - 40:
        grade = 'D'
    print("学生{}分数为{},等级为{}".format(i, scores[i], grade))

n = int(input()) 
nums = list(map(int, input().split())) 
counts = [0] * 101  
for num in nums:
    counts[num] += 1  
for i in range(1, 101):
    if counts[i] > 0:  
        print(f"{i}出现{counts[i]}次")

n = int(input())  
nums = list(map(int, input().split()))  
unique_nums = list(set(nums))  
for num in unique_nums:
    print(num, end=" ")  

import math


n = int(input())  
nums = list(map(int, input().split()))  
gcd = nums[0]  
for i in range(1, n):
    gcd = math.gcd(gcd, nums[i])  
print(gcd)

def is_non_decreasing(arr):
    for i in range(len(arr) - 1):
        if arr[i] > arr[i+1]:
            return "NO"
    return "YES"
T = int(input())  
for _ in range(T):
    n = int(input()) 
    arr = list(map(int, input().split()))  
    result = is_non_decreasing(arr) 
    print(result)

word1 = input()  
word2 = input() 
sorted_word1 = ''.join(sorted(word1))  
sorted_word2 = ''.join(sorted(word2)) 
if sorted_word1 == sorted_word2:
    print("YES")
else:
    print("NO")

import random


ball_count, slot_count = map(int, input().split())  
slots = [0] * slot_count  
for _ in range(ball_count):
    path = ""
    slot = 0
    for i in range(slot_count - 1):
        if random.random() <= 0.5:
            path += "L"
            slot += 1
        else:
            path += "R"
    slots[slot] += 1
    print(path)
print(" ".join(map(str, slots)))

lockers = [False] * 100 
for student in range(1, 101):
    for locker in range(student, 101, student):
        lockers[locker - 1] = not lockers[locker - 1]
open_lockers = [index + 1 for index, locker in enumerate(lockers) if locker]  
print(open_lockers)

n = int(input()) 
A = list(map(int, input().split())) 
m = int(input()) 
B = list(map(int, input().split())) 
C = [] 
i, j = 0, 0 
while i < n and j < m:
    if A[i] <= B[j]:
        C.append(A[i])
        i += 1
    else:
        C.append(B[j])
        j += 1
while i < n:
    C.append(A[i])
    i += 1
while j < m:
    C.append(B[j])
    j += 1
print(" ".join(map(str, C))) 

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值