关闭

chapter16test5

标签: c++
157人阅读 评论(0) 收藏 举报
分类:
#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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:50656次
    • 积分:2907
    • 等级:
    • 排名:第12185名
    • 原创:250篇
    • 转载:0篇
    • 译文:1篇
    • 评论:23条
    最新评论