【思路】:vector完美解决。注意用vector的动态数组方式,不然又其他的零。
【AC代码】:
#include <iostream> #include <algorithm> #include <vector> #include <cstdio> #include <cstring> using namespace std; #define MAX 100+5 int cmp(int a, int b) { return a < b; } int main() { //freopen("in.txt", "r", stdin); int n = 0, i = 0; //input cin >> n; vector<int> a(n); vector<int> :: iterator Iter; for (i = 0; i < n; i++) cin >> a[i]; //sort sort(a.begin(), a.end(), cmp); //delete for (Iter = a.begin()+1; Iter != a.end(); ) { int c = (*Iter), d = (*(Iter-1)); if ((*Iter) == (*(Iter-1))) Iter = a.erase(Iter); else Iter++; } //output cout << a.size() << endl; for (Iter = a.begin(); Iter != a.end(); Iter++) cout << (*Iter) << " "; return 0; }
原文:http://blog.csdn.net/weijj6608/article/details/44680891