您的位置:首页 > 编程语言 > C语言/C++

chapter16test4

2015-07-06 18:24 246 查看
#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++