chapter16test4

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int reduce(long ar[], int n);
int main()
{
long ar[8] = { 12309, 12307, 12306,12305, 12307, 12308,12305,12306 };
int num = reduce(ar, 8);
cout << "After reduced, we have " << num << " digit .\n";
return 0;
}
int reduce(long ar[], int n)
{
vector<long>line;
for (int i = 0; i < n; i++)
line.push_back(ar[i]);
sort(line.begin(), line.end());
line.erase(unique(line.begin(), line.end()),line.end());  //这里用到了unique()函数
return line.size();
}
阅读更多
文章标签: c++
个人分类: C++学习
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭