数组祛除重复
#include<iostream> #include<algorithm> #include<numeric> using namespace std; void helper(int a[],const int n) { sort(a,a+n); int k = 0; for(int i = 0;i< n;i++) { if(a[i] != a[k]) { a[k+1] = a[i]; k++; } } } int main() { int a[] = {7,8,8,4,5,6,7,8,8,9,1,2,3}; helper(a,13); for(int i = 0;i< 13;i++) { cout<<a[i]<<" "; } }
这个思路可以借鉴来着
berkeleysong
posted on 2014-05-18 22:47 berkeleysong 阅读(97) 评论(0) 编辑 收藏 举报