栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python ccf 题解历年100分(题目更新中)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python ccf 题解历年100分(题目更新中)

文章目录
  • 一、第一题
    • 1.1 2021年
      • 202109-1数组推导
      • 202104-1灰色直方图
    • 1.2 2020年
      • 202012-1期末预测之安全指数
      • 202009-1称检测点查询
      • 202006-1线性分类器
    • 1.3 2019年
      • 201912-1报数
      • 201909-1小明种苹果
      • 201903-1小中大
    • 1.4 2018年
      • 201812-1小明上学
      • 201809-1卖菜
      • 201803-1跳一跳
    • 1.5 2017年
      • 201712-1最小差值
      • 201709-1打酱油
      • 201703-1分蛋糕
    • 1.6 2016年
      • 201604-1折点计数
      • 201609-1最大波动
      • 201612-1中间数
    • 1.7 2015年
      • 201512-1数位之和
      • 201509-1数列分段
      • 201503-1图像旋转
    • 1.8 2014年
      • 201412-1门禁系统
      • 201409-1相邻数对
      • 201403-1相反数
    • 1.9 2013年
      • 201312-1出现次数最多的数
  • 第二题(待更新)

一、第一题

1.1 2021年 202109-1数组推导

# -*- coding: utf-8 -*-
"""
@Time : 2021-10-04 9:28
@Author : oax_knud
@File :202109-1数组推导.py
@IDE :PyCharm
"""
import math

num=int(input())
B=[]
B = list(map(int, input().split()))
sum_max=sum(B)
sum_min=B[0]
min=min(B)
flag=1
for i in range(num):
    if i==num-1:
        break
    if i==0 and B[i+1]==B[i]:
        flag=0
        sum_min=sum_min+0
    elif i!=num-1 and B[i+1]==B[i]:
        flag=0
    elif B[i+1]!=B[i]:
        sum_min=sum_min+B[i+1]
print(sum_max)
if flag==0:
    print(sum_min)
elif flag==1:
    print(sum_max)
202104-1灰色直方图

# -*- coding: utf-8 -*-
"""
@Time : 2021-10-04 12:07
@Author : oax_knud
@File :202104-1灰色直方图.py
@IDE :PyCharm
"""

constraint=list(map(int,input().split()))
ans_list=[0 for i in range(constraint[2])]
for i in range(constraint[0]):
    row=[]
    row=list(map(int,input().split()))
    for k in range(constraint[1]):
        ans_list[row[k]]=ans_list[row[k]]+1
for i in range(constraint[2]):
    print(ans_list[i],end=" ")
1.2 2020年 202012-1期末预测之安全指数

# -*- coding: utf-8 -*-
"""
@Time : 2021-10-04 16:46
@Author : oax_knud
@File :202012-1期末预测之安全指数.py
@IDE :PyCharm
"""
n=int(input())
score=[]
ws=[]
for i in range(n):
    row=list(map(int,input().split()))
    ws.append(row)
    score.append(row[0]*row[1])
print(max(sum(score),0))
202009-1称检测点查询

# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 9:05
@Author : oax_knud
@File :202009-1称检测点查询.py
@IDE :PyCharm
"""
import math
n,X,Y=list(map(int,input().split()))#限制条件
distance=[]
for i in range(n):
    x,y=list(map(int,input().split()))
    temp_dis=math.sqrt((x-X)*(x-X)+(y-Y)*(y-Y))
    group=[]
    group.append((i+1))
    group.append(temp_dis)
    distance.append(group)
new_dis=sorted(distance,key=(lambda  x:x[1]),reverse=False)
print(new_dis[0][0])
print(new_dis[1][0])
print(new_dis[2][0])

202006-1线性分类器


n,m=map(int,input().split())
x=[]
y=[]
label=[]
for i in range(n):
    a,b,c=input().split()
    x.append(int(a))
    y.append(int(b))
    label.append(c)
for i in range(m):
    a,b,c=map(int, input().split())
    A_class=[]
    B_class=[]
    for j in range(n):
        if a+x[j]*b+y[j]*c<0:
            A_class.append(label[j])
        elif a+x[j]*b+y[j]*c>0:
            B_class.append(label[j])
    if len(list(set(A_class)))==1 and len(list(set(B_class)))==1:
        print('Yes')
    else:
        print('No')
1.3 2019年 201912-1报数

n=int(input())
count=0
jump=[0 for i in range(4)]
# name=["甲","乙","丙","丁"]
jump_index=0
jump_num=[]
for i in range(1,10000):
    if count==n:
        break
    if i%7==0 or i%10==7 or (i // 10)%10==7 or (i//100)==7:#跳
        jump[jump_index]+=1
        # print(name[jump_index],"跳了",i)
        jump_index=(jump_index+1)%4
        jump_num.append(i)
        continue
    # print(name[jump_index], "读了", i)
    count+=1
    jump_index=(jump_index+1)%4
for i in range(len(jump)):
    print(jump[i])
201909-1小明种苹果


# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 19:40
@Author : oax_knud
@File :201909-1小明种苹果.py
@IDE :PyCharm
"""
N,M=list(map(int,input().split()))
apple_tree=[]
for i in range(N):
    row=list(map(int,input().split()))
    apple_tree.append(row)
max_apple=[]
sum_apple=0
for i in range(N):
    temp_apple=0
    for j in range(1,M+1):
        temp_apple+=abs(apple_tree[i][j])
        #temp_apple=abs(apple_tree[i][1]+apple_tree[i][2]+apple_tree[i][3])
    max_apple.append(temp_apple)
    sum_apple+=apple_tree[i][0]
sum_apple=sum_apple-sum(max_apple)
index_max=max_apple.index(max(max_apple))+1
print(sum_apple,index_max,max(max_apple))



201903-1小中大
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 19:29
@Author : oax_knud
@File :201903-1小中大.py
@IDE :PyCharm
"""
import math
n=int(input())
row=list(map(int,input().split()))
ans=[]
ans.append(max(row))
ans.append(min(row))
row.sort()
if n%2==0:
    num=round((row[len(row)//2]+row[len(row)//2-1])/2,1)
    if math.modf(num)[0]==0:
        num=int(num)
    ans.append(num)
elif n%2==1:
    ans.append(row[len(row)//2])
ans.sort(reverse=True)
for i in range(len(ans)):
    print(ans[i],end=" ")
1.4 2018年 201812-1小明上学
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 19:22
@Author : oax_knud
@File :201812-1小明上学.py
@IDE :PyCharm
"""
r,y,g=list(map(int,input().split()))
n=int(input())
time=0
for i in range(n):
    row=list(map(int,input().split()))
    if row[0]==0 or row[0]==1:
        time+=row[1]
    elif row[0]==2:
        time+=(row[1]+r)
    elif row[0]==3:
        continue
print(time)
201809-1卖菜
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 19:16
@Author : oax_knud
@File :201809-1卖菜.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
ans=[]
for i in range(n):
    if i==0:
        ans.append(int((row[i]+row[i+1])/2))
    elif i==n-1:
        ans.append(int((row[i]+row[i-1])/2))
    else:
        ans.append(int((row[i]+row[i+1]+row[i-1])/3))
for i in range(n):
    print(ans[i],end=" ")
201803-1跳一跳
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 19:08
@Author : oax_knud
@File :201803-1跳一跳.py
@IDE :PyCharm
"""
row=list(map(int,input().split()))
length=len(row)
score=0
temp_two=2
for i in range(length-1):
    if row[i]==1:
        score+=1
        temp_two=2
    elif row[i]==2:
        if i==0 or row[i-1]==1:
            score+=temp_two
        elif row[i-1]==2:
            temp_two+=2
            score+=temp_two
print(score)
1.5 2017年 201712-1最小差值
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 19:03
@Author : oax_knud
@File :201712-1最小差值.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
row.sort()
ans=[]
for i in range(1,n):
    temp=row[i]-row[i-1]
    ans.append(temp)
print(min(ans))
201709-1打酱油
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 18:58
@Author : oax_knud
@File :201709-1打酱油.py
@IDE :PyCharm
"""
n=int(input())
count=0
while n>0:
    if n>=50:
        n-=50
        count+=7
    elif n>=30:
        n-=30
        count+=4
    else:
        count+=(n//10)
        n=0
print(count)

201703-1分蛋糕
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 18:31
@Author : oax_knud
@File :201703-1分蛋糕.py
@IDE :PyCharm
"""
n,k=list(map(int,input().split()))
row=list(map(int,input().split()))
count=0
index=0
temp_sum=0
for i in range(n):
    temp_sum=sum(row[index:i+1])
    # ans.append(temp_sum)
    if temp_sum>=k:
        count+=1
        index=i+1
    else:
        continue
if temp_sum 
1.6 2016年 
201604-1折点计数 
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 17:54
@Author : oax_knud
@File :201604-1折点计数.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
count=0
for i in range(1,n-1):
    if row[i]row[i+1] and row[i]>row[i-1]:
        count+=1
print(count)
201609-1最大波动
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 17:58
@Author : oax_knud
@File :201609-1最大波动.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
abs_row=[]
for i in range(n-1):
    abs_row.append(abs(row[i]-row[i+1]))
print(max(abs_row))
201612-1中间数
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 18:01
@Author : oax_knud
@File :201612-1中间数.py
@IDE :PyCharm
"""
def cal_min_max(num,row):
    min_number=0
    for i in range(len(row)):
        if row[i] 
1.7 2015年 
201512-1数位之和 
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 17:52
@Author : oax_knud
@File :201512-1数位之和.py
@IDE :PyCharm
"""
row=list(map(int,input()))
print(sum(row))
201509-1数列分段
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 17:49
@Author : oax_knud
@File :201509-1数列分段.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
count=1
for i in range(n-1):
    if row[i]!=row[i+1]:
        count+=1
    elif row[i]==row[i+1]:
        continue
print(count)

201503-1图像旋转
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 16:53
@Author : oax_knud
@File :201503-1图像旋转.py
@IDE :PyCharm
"""
n,m=list(map(int,input().split()))
img=[]
for i in range(n):
    row=list(map(int,input().split()))
    img.append(row)
for i in range(m):
    for j in range(n):
        print(img[j][m-i-1],end=" ")
    print("")

1.8 2014年 201412-1门禁系统
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 16:49
@Author : oax_knud
@File :201412-1门禁系统.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
num=[[i,0] for i in range(n+1)]
for i in range(n):
    id=row[i]
    num[id][1]+=1
    print(num[id][1],end=" ")

201409-1相邻数对
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 16:42
@Author : oax_knud
@File :201409-1相邻数对.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
count=0
row.sort()
for i in range(n-1):
    if row[i+1]-row[i]==1:
        count+=1
print(count)
201403-1相反数
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 16:37
@Author : oax_knud
@File :201403-1相反数.py
@IDE :PyCharm
"""
N=int(input())
row=list(map(int,input().split()))
count=0
for i in range(N):
    if row[i]==0:
        continue
    for j in range(N-i):
        if row[i]+row[j+i]==0:
            count+=1
            row[j+i]=0
            break
print(count)
1.9 2013年 201312-1出现次数最多的数
# -*- coding: utf-8 -*-
"""
@Time : 2021-10-13 16:12
@Author : oax_knud
@File :201312-1出现次数最多的数.py
@IDE :PyCharm
"""
n=int(input())
row=list(map(int,input().split()))
num=[[i,0] for i in range(1,10001)]
for i in range(n):
    temp_num=row[i]
    num[temp_num-1][1]+=1
    # print(num[temp_num-1])
# print(num)
ans=sorted(num,key=(lambda x:x[1]),reverse=True)
print(ans[0][0])

第二题(待更新)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/321677.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号