solution.json 1.8 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "e0ed26c00e394a4bb732453c9cf34c85",
  "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量",
  "title": "一个整数的序列,要求对其重新排序",
  "desc": [
    {
      "content": "\n<p>一个整数的序列&#xff0c;要求对其重新排序。排序要求:\n1.奇数在前&#xff0c;偶数在后&#xff1b;\n2.奇数按从大到小排序&#xff1b;\n3.偶数按从小到大排序。<br />\n输入一行&#xff0c;包含整数个数n&#xff0c; n个整数值&#xff0c;彼此以一个空格分开。\n按照要求排序后输出一行&#xff0c;包含排序后的n 个整数。\n</p>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <iostream>\n#include <algorithm>\nusing namespace std;\nbool cmp(int a, int b){\n    int x = a % 2;\n    int y = b % 2;\n    if(x == y)\n        if(x == 0)\n            return a < b;\n        else\n            return a > b;\n    else\n        return x > y;\n}\nint main()\n{\n    int n, i;\n    cin >> n;\n    int a[n];\n    for(i = 0; i < n; i++)\n        cin >> a[i];\n    sort(a, a+n, cmp);\n    for(i = 0; i < n; i++)\n        cout << a[i] << \" \";\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-18b330b06c254136bf00850f53290b0b",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470146"
}