{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "efb125b11d0d4507b438f6441c32718a",
  "keywords": "排序",
  "title": "以特殊格式处理连续增加的数字",
  "desc": [
    {
      "content": "\n给出一串数字， 程序要把数字按照这样的格式输出，把连续增加的数字用 [x-y] 的形式表示，只显示这一组顺序数字的首位两个数字，不连续增加的数字单独列出。 例如：\n输入：1, 2, 3, 4, 5, 8, 10, 11, 12, 13, 20, 21, 22; \n输出：[1-5] [8] [10-13] [20-22]。",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "seq = list(map(int, input().split(',')))\ntmp = [seq[0]]\nall_list = []\nfor n in range(len(seq)):\n\tif n == len(seq) - 1:\n\t\tall_list.append(tmp)\n\t\tbreak\n\tif seq[n + 1] - seq[n] == 1:\n\t\ttmp.append(seq[n + 1])\n\telse:\n\t\tall_list.append(tmp)\n\t\ttmp = [seq[n + 1]]\nfor a in all_list:\n\tif len(a) > 1:\n\t\tprint('[%s-%s]' % (a[0], a[-1]))\n\telse:\n\t\tprint('[%s]' % a[0])",
    "language": "python"
  },
  "node_id": "dailycode-a348977e517f4b358abaf20c42988cbf",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600469994"
}