【c/c++】Simple Sorting

题目链接

题目描述

You are given an unsorted array of integer numbers. Your task is to sort this array and kill possible duplicated elements occurring in it.
给你一个未排序的整数数组。您的任务是对该数组进行排序,并消除其中可能出现的重复元素。

输入描述

For each case, the first line of the input contains an integer number N representing the quantity of numbers in this array(1≤N≤1000). Next N lines contain N integer numbers(one number per each line) of the original array.
对于每种情况,输入的第一行包含一个整数N,表示这个数组中数字的数量(1≤N≤1000)。接下来的N行包含原始数组的N个整数(每行一个数字)。

输出描述

For each case ,outtput file should contain at most N numbers sorted in ascending order. Every number in the output file should occur only once.
对于每种情况,输出文件最多包含N个按升序排序的数字。输出文件中的每个数字应该只出现一次。

输入示例

6
8 8 7 3 7 7

输出示例

3 7 8

思路

直接用排序算法来做,遇到相同的数跳过,或者使用sort()函数排序

代码
#include<bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N);
    cout<<a[0]<<" ";
    for(int i=1;i<N;i++){
        if(a[i]!=a[i-1]){
            cout<<a[i]<<" ";
        }
    }
    return 0;
}
Tip:
  • sort(首元素地址,尾元素地址,比较函数(非必填))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶柖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值