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

chapter16test5

2015-07-06 18:45 337 查看
#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

template<class T>

int reduce(T ar[], int n);

int main()

{
long ar[8] = { 12309, 12307, 12306, 12305, 12307, 12308, 12305, 12306 };
string say[5] = { "Big", "fish", "fish", "big", "scereaful" };
int num = reduce(ar, 8);
cout << "After reduced, we have " << num << " digit .\n";
int number = reduce(say, 5);
cout << "After reduced, we have " << number << " words .\n";
return 0;

}

template<class T>

int reduce(T ar[], int n)

{
vector<T>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());
return line.size();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++