社团关联
提交数: 308, 通过率: 60.06%, 平均分: 60.17
题目描述:
为进一步提高社团开设时段的合理性,学校团委收集并整理了某届学生在校三年期间的社团
数据(每位学生每年均选择一个社团参加),用于分析并统计各个社团间的关联性。 关联性指
的是三年中某两个社团被同一个学生选择参加,则称这对社团关联 1 次。
输入格式:
第一行n,表示输入n行内容。
每行内容由学号,姓名,三个社团名组成。
输出格式:
输出社团关联次数(非零)的排行榜。
数据范围:
\( n \lt 100 \)
样例输入:
6 20210104 ZhengXiao debating society/Music Club/Law Society 20210105 JiangChenggui debating society/Sinology Society/Poetry Society 20210107 LiSi debating society/Music Club/Law Society 20210108 WangWu debating society/Sinology Society/Poetry Society 20210110 Shuyi debating society/Music Club/Law Society 20210111 LiuXiaoqi debating society/Sinology Society/Poetry Society
样例输出:
Ranking of Association Times: debating society / Law Society association, The number of associations is: 3 debating society / Poetry Society association, The number of associations is: 3 debating society / Music Club association, The number of associations is: 3 debating society / Sinology Society association, The number of associations is: 3 Law Society / debating society association, The number of associations is: 3 Law Society / Music Club association, The number of associations is: 3 Poetry Society / debating society association, The number of associations is: 3 Poetry Society / Sinology Society association, The number of associations is: 3 Music Club / debating society association, The number of associations is: 3 Music Club / Law Society association, The number of associations is: 3 Sinology Society / debating society association, The number of associations is: 3 Sinology Society / Poetry Society association, The number of associations is: 3
提示:
请完善程序:
def proc(x):
x = x+"/"
i = j = 0; lst = []
n = len(x)
while j < n:
if x[j] == "/":
lst.append( x[i:j] ) #将 x[i:j]添加到列表 lst 末尾
__________________ #填空1
j += 1
return lst
def freq(x):
for i in range( len(x) - 1 ):
for j in range( ________________ ): #填空2
m = st[ x[i] ]
n = st[ x[j] ]
f[m][n] += 1
f[n][m] += 1
data = [ ]
# 将数据逐行添加到列表 data 中,
# 存储内容为[["20210101", "朱梓轩", "魔方社/飞羽社/动漫社"],……]
n = int( input() )
for i in range( n ):
line = input()
k = j = 0
datatmp = []
while line[j]!=' ' : j += 1
datatmp.append( line[ k : j ] )
j += 1
k = j
while line[j]!=' ' : j += 1
datatmp.append( line[ k : j ] )
datatmp.append( line[ j+1: ] )
data.append( datatmp )
st = {"Cartoon and Animation Society":0,"debating society":1,"Law Society":2,"Rubik's Cube Society":3,"Poetry Society":4,"Music Club":5,"Photography Society":6,"society of calligraphy and painting":7,"The Flying Feather Society":8,"Sinology Society":9}
st1 = {0:"Cartoon and Animation Society",1:"debating society",2:"Law Society",3:"Rubik's Cube Society",4:"Poetry Society",5:"Music Club",6:"Photography Society",7:"society of calligraphy and painting",8:"The Flying Feather Society",9:"Sinology Society"}
n = len(st)
f=[ [0 for i in range(n)] for j in range(n) ] # 生成 n 行 n 列初值均为 0 的列表 f
for i in data:
_____________________ #填空2
freq( cur )
a = []
for i in range(n):
for j in range(n):
a.append( [ f[i][j], i, j ] )
a.sort( key = lambda x : x[0], reverse = True)
print("Ranking of Association Times:")
for it in a:
if __________________ : #填空4
print(f"{st1[it[1]]} / {st1[it[2]]} association, The number of associations is: {it[0]}")
时间限制: 1000ms空间限制: 256MB
来源: 2024.01协作题T15