美文网首页
STL-unique()数组去重

STL-unique()数组去重

作者: Co_zy | 来源:发表于2018-08-02 12:51 被阅读0次
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
    int n;
    int input[1005];
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&input[i]);
        sort(input,input+n);
        n = unique(input, input + n) - input;//使用STL自带去重函数,返回值为最后一个元素的位置(地址)
//    for(int i = 0; i < n; i ++)
//    {
//        cout << input[i] << " ";
//    }
        int j;
        scanf("%d",&j);
        printf("%d\n",input[j-1]);
    }
    return 0;
}

相关文章

网友评论

      本文标题:STL-unique()数组去重

      本文链接:https://www.haomeiwen.com/subject/aubjvftx.html