标签:com 元素 cst using \n ima scan can str
//在vector中的应用
#include <iostream> #include<cstdio> #include<vector> #include<algorithm> using namespace std; vector<int> a;vector<int>::iterator p; int main() { int n;scanf("%d",&n); for(int i=1;i<=n;i++){int x;scanf("%d",&x); a.push_back(x);} sort(a.begin(),a.end()); printf("vector排序:\n"); for(p=a.begin();p<a.end();p++) printf("%d%c",*p,p==a.end()-1?‘\n‘:‘ ‘); vector<int>::iterator it=unique(a.begin(),a.end()); printf("vector‘去重’:\n"); for(p=a.begin();p<it;p++) printf("%d%c",*p,p==it-1?‘\n‘:‘ ‘); printf("‘去重’后的整个vector:\n"); for(p=a.begin();p<a.end();p++) printf("%d%c",*p,p==a.end()-1?‘\n‘:‘ ‘); a.erase(it,a.end()); printf("vector‘去重’后删去多余元素:\n"); for(p=a.begin();p<a.end();p++) printf("%d%c",*p,p==a.end()-1?‘\n‘:‘ ‘); return 0; }
//在数组中的应用类似
运行结果:
标签:com 元素 cst using \n ima scan can str
原文地址:https://www.cnblogs.com/lllxq/p/9552589.html