程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The fourth intelligence cup | practice competition | Python solution ideas

編輯:Python

List of topics

  • Introduction
  • A [#4 Practice games ] The number that meets the condition
  • B [#4 Practice games ] Elected representative
  • C [#4 Practice games ] Score statistics
  • D [#4 Practice games ] Recite the answer
  • E [#4 Practice games ] Beat the drum to spread the flowers

Introduction

A few days ago, there was a practice match in the wisdom cup , Bloggers take the postgraduate entrance examination in their spare time , Did it
I can't update the article for a long time , I'm really busy taking the postgraduate entrance examination
I happened to see a lot of fan messages The title of the wisdom Cup
There is no corresponding tutorial on the Internet ( This is also a The first article of the whole network Is that right Ah ha ha ha , But it is really a very simple topic )
Bloggers have not systematically learned data structures and algorithms ( I have been learning operating system and composition principle since the beginning of school )
I have written the detailed explanation of five questions in my own way
I hope the big guys can give me more advice
If there are big men, they can pass on their postgraduate entrance examination experience
Be deeply grateful

A [#4 Practice games ] The number that meets the condition


Brute force

N,k = map(int,input().split())
init_num = N
while True:
if str(init_num).count('3') == k:
print(init_num)
break
else:
init_num += 1

B [#4 Practice games ] Elected representative


Using the principle of similar word statistics , The code has comments

timing = int(input())
xuehao_list = list(map(int,input().split()))
dict_num = {}
new_list = []
if len(xuehao_list) == timing:
for i in xuehao_list:
if i in dict_num:
dict_num[i] += 1
else:
# there new_list Ensure that the non repeated numbers are output in the input sequence
new_list.append(i)
dict_num[i] = 1
for i in new_list:
print(i,end=' ')

C [#4 Practice games ] Score statistics


You can't use it here import Import math, Otherwise, it will keep reporting errors , I've been struggling for a long time

geshu = int(input())
stu_list = []
for i in range(geshu):
stu_list.append(input().split())
dict_stu_list = {}
for stu_grade in stu_list:
temp = (int(stu_grade[2])**0.5) * 10
grade = temp * 0.6 + 0.4 * int(stu_grade[1])
# If there is a decimal point , Rounding up
if int(str(grade).split('.')[1])>0:
grade += 1
grade = int(grade)
dict_stu_list[stu_grade[0]] = grade
# Sort the dictionary
ord_dict_stu = sorted(dict_stu_list.items(),key=lambda x:x[1],reverse=True)
for i in ord_dict_stu:
print("{} {}".format(i[0],i[1]))

D [#4 Practice games ] Recite the answer


There's nothing to say about this question , It's a matter of logic , however , Note: do not store in a dictionary , Because the input question has duplicate questions , But there are no repeated answers , Pay attention to this pit

daan,ti_= map(int,input().split())
dict_daan = {}
dict_wenti = []
dict_xuanxiang = {1:'A',2:'B',3:'C',4:'D'}
for i in range(daan):
ti,daan = input().split()
dict_daan[ti] = daan
for i in range(ti_):
ti_2,A,B,C,D = input().split()
dict_wenti.append([ti_2,A,B,C,D])
for wenti in dict_wenti:
for daan in dict_daan.items():
if wenti[0] == daan[0]:
print(dict_xuanxiang[wenti.index(dict_daan[wenti[0]])])

E [#4 Practice games ] Beat the drum to spread the flowers


There may be a better algorithm to solve this problem , However, I am not very proficient in data structure , I plan to learn data structure in winter vacation , A brush leedcode Improve the algorithm idea .

n,m,k= map(int,input().split())
init_list = list(map(int,input().split()))
new_list = []
for j in range(5):
for i in range(m):
temp = (init_list[i]+k)%n
if temp>n-1:
temp = 0
init_list[i] = temp
for i in init_list.copy():
new_list.append(i)
print(n-len(set(new_list)))

I wish you all success in the postgraduate entrance examination !!!!!!!!!!!!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved