华为商城,每一秒第一个购买的人可以免单,同时刻的人都可以免单。
输入N组数据(各种年月不同时刻的),问怎么算免单人数
订单信息诸如:
2020-05-11 16:47:22.001
2020-05-11 16:47:52.002
2020-05-11 16:48:07.003
输出:3
import sys
#列表存储订单中不同的秒数
list_seconds = []
list = []
result = {}
count = 0
#如果是系统输入,用注释的这段
# for line in sys.stdin:
# x, y = line.split(".")
# list.append([x,y])
while True:
ss = input()
if ss == "":
break
mm = ss.split(".")
list.append([mm[0],mm[1]]) #将输入的订单,按秒分别存储到列表list中
for i in list:
if i[0] not in list_seconds:
list_seconds.append(i[0]) #将列表list中相同的时间写进list_seconds中
for i in list_seconds:
list_moment = []
for j in list:
if j[0] == i:
list_moment.append(j[1])
result[i] = list_moment #将同一秒中,所有订单的时刻写进result中
for i in result.values():
sorted(i)
count += i.count(i[0]) #将同一秒中的时刻排序,取第一个,求count数,累计相加,得出结果
print(count)