{ "question_id": 704613, "question_title": "排序", "question_content": "试题描述\n 由键盘上输入n个整数,请将这些数从大到小排序,然后输出排序后的数列。\n输入\n 输入包含两行:\n 第一行是n(1 <= n <= 1000)。\n 第二行是n个整数,邻近两数之间用一个空格隔开。\n输出\n 输出排序后的n个整数,邻近两数之间用一个空格隔开。\n输入示例\n 5\n 8 2 5 1 2\n输出示例\n 8 5 2 2 1\n数据范围\n 输入和输出均为int范围的整数", "difficulty": "简单", "answer_id": 598037, "answer_content": "又是你.\n\n```\n #include\nusing namespace std;\nint main() {\n\tint n,tmp;\n\tcin >> n;\n\tint *a = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> a[i];\n\tfor (int i = 0; i < n - 1; i++) {\t\t//冒泡排序\n\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\tif (a[i] < a[j]) {\n\t\t\t\ttmp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 0; i < n; i++) {\n\t\tcout << a[i];\n\t\tif (i != n - 1)\n\t\t\tcout << \" \";\n\t}\n\treturn 0;\n}\n```\n\n", "tag_name": "c++", "cpp": " #include\nusing namespace std;\nint main() {\n\tint n,tmp;\n\tcin >> n;\n\tint *a = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> a[i];\n\tfor (int i = 0; i < n - 1; i++) {\t\t\n\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\tif (a[i] < a[j]) {\n\t\t\t\ttmp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 0; i < n; i++) {\n\t\tcout << a[i];\n\t\tif (i != n - 1)\n\t\t\tcout << \" \";\n\t}\n\treturn 0;\n}", "topic_link": "https://bbs.csdn.net/topics/600470259", "status": 1, "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/51.ipynb?type=file" }, "notebook_enable": 1, "author": "csdn.net" }