import json
with open(r"..\题库0.3\Problems.json","r",encoding = "utf8") as f:
    database = f.read()
idlist = list(json.loads(database).keys())

def generate_exp(id_list):
    if not len(id_list) == 0:
        exp_list = []
        start = id_list[0]
        current = start
        end = start
        for id in id_list[1:]:
            # print(id,current)
            if int(id)-1 == int(current):
                current = id
                end = id
            else:
                if not start == end:
                    exp_list.append('"'+start+":"+end+'"')
                else:
                    exp_list.append('"'+start+'"')
                start = id
                current = id
                end = id
        if not start == end:
            exp_list.append('"'+start+":"+end+'"')
        else:
            exp_list.append('"'+start+'"')
    return exp_list


used_list = generate_exp(idlist)

for group in range(len(used_list)-1):
    print("首个空闲id: %s, 直至: %s"%(str(int(used_list[group][-7:-1])+1).zfill(6),str(int(used_list[group+1][1:7])-1).zfill(6)))
print("首个空闲id: %s, 直至: %s"%(str(int(used_list[-1][-7:-1])+1).zfill(6),"999999"))
# freeidlist = {}
# for id in idlist:
#     if not str(int(id)+1).zfill(6) in idlist:
#         freeidlist[id] = ""
# for id in freeidlist:
#     largeridlist = [usedid for usedid in idlist if usedid > id]
#     if not largeridlist == []:
#         freeidlist[id] = str(int(min(largeridlist))-1).zfill(6)
#     else:
#         freeidlist[id] = "999999"
# for id in freeidlist:
#     print("首个空闲id:",str(int(id)+1),", 直至",freeidlist[id])