chapter16test5

来源:互联网 发布:软件的营销策略 编辑:程序博客网 时间:2024/05/08 04:37
#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();
}
0 0