{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "首个空闲id: 13287 , 直至 020000\n",
      "首个空闲id: 21441 , 直至 030000\n",
      "首个空闲id: 31204 , 直至 999999\n"
     ]
    }
   ],
   "source": [
    "import os,re,json\n",
    "with open(r\"..\\题库0.3\\Problems.json\",\"r\",encoding = \"utf8\") as f:\n",
    "    database = f.read()\n",
    "idlist = list(json.loads(database).keys())\n",
    "freeidlist = {}\n",
    "for id in idlist:\n",
    "    if not str(int(id)+1).zfill(6) in idlist:\n",
    "        freeidlist[id] = \"\"\n",
    "for id in freeidlist:\n",
    "    largeridlist = [usedid for usedid in idlist if usedid > id]\n",
    "    if not largeridlist == []:\n",
    "        freeidlist[id] = str(int(min(largeridlist))-1).zfill(6)\n",
    "    else:\n",
    "        freeidlist[id] = \"999999\"\n",
    "for id in freeidlist:\n",
    "    print(\"首个空闲id:\",str(int(id)+1),\", 直至\",freeidlist[id])\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.15 ('mathdept')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.15"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "42dd566da87765ddbe9b5c5b483063747fec4aacc5469ad554706e4b742e67b2"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
