2025年华中科技大学计算机考研复试机试真题(附 AC 代码 + 解题思路)
2026/6/8 6:49:57 网站建设 项目流程

2025年华中科技大学计算机考研复试机试真题

2025年华中科技大学计算机考研复试上机真题

历年华中科技大学计算机考研复试上机真题

历年华中科技大学计算机考研复试机试真题

更多学校题目开源地址:https://gitcode.com/verticallimit1/noobdream

N 诺 DreamJudge 题库:输入 “学校名称” 即可筛选该校历年机试真题,题目均在考纲范围内,按难度自动排序。还可搭配《计算机考研机试攻略》刷题,书中题目可通过题号直接在题库中查找。

排序去重

题目描述

Time Limit: 1000 ms
Memory Limit: 256 mb

输入一个长度为n的数组,先将其进行排序输出,然后对排序后的结果去重再次输出

输入输出格式
输入描述:

如题

输出描述:

如题

输入输出样例
输入样例#:
6 3 2 3 6 5 6
输出样例#:
2 3 3 5 6 6 2 3 5 6

代码一

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. cin>>n;
  6. vector<int>nums(n);
  7. for(int i=0;i<n;i++){
  8. cin>>nums[i];
  9. }
  10. sort(nums.begin(),nums.end());
  11. for(int i=0;i<n;i++){
  12. cout<<nums[i]<<" ";
  13. }
  14. cout<<endl;
  15. cout<<nums[0]<<" ";
  16. for(int i=1;i<n;i++){
  17. if(nums[i]==nums[i-1]){
  18. continue;
  19. }
  20. cout<<nums[i]<<" ";
  21. }
  22. return 0;
  23. }

代码二

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const int maxn = 100005;
  5. int main() {
  6. int n;
  7. cin >> n;
  8. vector<int> arr(n);
  9. set<int> st;
  10. for (int i = 0; i < n; i++){
  11. int temp;
  12. cin >> temp;
  13. arr[i] = temp;
  14. st.insert(temp);
  15. }
  16. sort(arr.begin(), arr.end());
  17. for (int i = 0; i < n; i++){
  18. cout << arr[i] << ' ';
  19. }
  20. cout << '\n';
  21. for (int i : st){
  22. cout << i << ' ';
  23. }
  24. //system("pause");
  25. return 0;
  26. }

代码三

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. cin>>n;
  6. vector<int> a(n);
  7. for(int i = 0; i<n; i++) cin>>a[i];
  8. sort(a.begin(),a.end());
  9. for(int i = 0; i<n; i++) cout<<a[i]<<" ";
  10. cout<<endl;
  11. int res = a[0];
  12. cout<<res<<" ";
  13. for(int i = 1; i<n; i++){
  14. if(res != a[i]){
  15. res = a[i];
  16. cout<<res<<" ";
  17. }
  18. }
  19. cout<<endl;
  20. return 0;
  21. }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询