You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
626 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<bits/stdc++.h>
using namespace std;
//数组长度
const int n=10;
/*
功能:打印一维数组
作者:黄海
时间2019-10-29
*/
void printArray(int a[n]) {
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout<<endl;
}
int main() {
// 测试数据
int a[n] = { 0, 7, 7, 6, 1, 1, 5, 5, 8, 9 };
//数组长度
int length= (sizeof(a) / sizeof(a[0]));
//去重前打印输出
printArray(a);
//先排序再去重(由小到大:less由大到小greater)
sort(a, a + n, less<int>() );
//开始去重
int n = unique(a, a + length) - a;
//输出去重后的数组
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
return 0;
}