[求助]有关连号分类问题
数据文本(data.txt)中有N行数据,现要将冒号后面的数据进行分类,分类规则如下:无连号:01,03,05,07,09,21这种类型分为一类
单二连号:01,02,05,11,21,24 这种类型分为一类
双二连号:01,02,14,15,17,22 这种类型分为一类
三二连号:01,02,13,14,27,28 这种类型分为一类
单三连号:01,02,03,11,15,17 这种类型分为一类
双三连号:01,02,03,10,11,12 这种类型分为一类
二连号+三连号:01,02,15,20,21,22 这种类型分为一类
二连号+四连号:01,02,18,19,20,21 这种类型分为一类
三连号+二连号:01,02,03,21,23,28,29 这种类型分为一类
四连号+二连号:001,02,03,04,21,22 这种类型分为一类
四连号:01,02,03,04,11,16,17 这种类型分为一类
五连号:01,02,03,04,5,17 这种类型分为一类
六连号:01,02,03,04,5,6 这种类型分为一类
每种分类独立用一个文本装。
以下是data.txt部分数据
A10A21A34A44A57A74:01,02,05,16,18,19
A2A11A27A30A45A60:01,02,06,08,12,19
A6A10A16A26A41A60:01,02,07,08,10,11
A1A7A14A35A48A56:03,06,17,18,19,30
A1A7A35A52A53A56:03,06,17,18,30,32
A26A33A52A56A63A74:03,06,17,20,21,22
A2A7A24A56A66A68:03,06,17,20,23,30
A2A5A38A55A63A74:05,12,16,19,21,33
A1A11A17A60A67A74:05,12,16,19,22,27
A2A9A17A46A56A57:05,12,17,19,21,27
A5A6A22A38A56A71:05,12,17,20,21,32
A3A7A20A30A60A63:06,08,10,12,18,23
A2A3A24A35A45A60:06,08,10,12,19,30
A4A27A36A38A47A51:06,08,10,14,17,22
A3A20A44A50A55A74:06,08,10,14,18,30
A2A23A28A30A34A55:06,08,10,15,26,28
A3A4A30A40A55A79:06,08,10,18,19,23
A1A24A26A64A70A77:08,19,20,22,23,33
A2A19A54A66A77A79:08,19,20,23,27,33
A13A18A30A60A62A72:09,10,11,12,18,23
A2A16A29A33A60A75:09,10,11,12,20,26
A5A7A18A58A63A79:14,17,19,20,23,33
A4A5A38A57A75A77:14,18,19,20,21,31
A5A8A9A28A44A57:14,18,19,21,25,27
A4A5A38A68A75A77:14,18,20,21,31,32
A1A5A26A50A60A68:14,20,22,23,30,32
A1A4A19A48A67A77:15,16,19,20,22,33 有没有哪位热心的朋友帮忙解答一下呢? 要别人帮你写代码吧 建议弄成悬赏鱼币贴 更快~ def kinds(data):
if data.count("1") == 0:
return 0
if data.count("11111") == 1:
return 6
if data.count("1111") == 1:
return 5
if data.count("111") == 1 and data.count("1") == 3:
return 4
if data.count("111") == 1 and data.count("1") == 4:
if data[:3] == "111":
return 42
else:
return 24
if data.count("11") == 2 and data.count("1") == 4:
return 33
if data.count("11") == 1 and data.count("1") == 3:
if "11" in data[:4]:
return 32
else:
return 23
if data.count("11") == 1 and data.count("1") == 2:
return 3
if data.count("11") == 0 and data.count("1") == 3:
return 222
if data.count("11") == 0 and data.count("1") == 2:
return 22
if data.count("1") == 1:
return 2
f = open("data.txt","r",encoding = "utf-8")
data = f.readlines()
for i in data:
if i:
k = i.split(":")
v = .split(",") ]
data = "".join(-v) if v-v<10 else "9" for y in range(len(v)-1)])
print(i[:-1],"-->",kinds(data),"连号") qq1151985918 发表于 2021-3-26 13:52
非常感谢你的帮助,虽然还没完全看的明白算法,但是我会从中慢慢学习的。再次感谢。
页:
[1]