時間限制:1 秒
內存限制:32 兆
特殊判題:否
提交:3971
解決:1483
You are given an unsorted array of integer numbers. Your task is to sort this array and kill possible duplicated elements occurring in it.
For each case, the first line of the input contains an integer number N representing the quantity of numbers in this array(1≤N≤1000). Next N lines contain N integer numbers(one number per each line) of the original array.
For each case ,outtput file should contain at most N numbers sorted in ascending order. Every number in the output file should occur only once.
6 8 8 7 3 7 7
3 7 8
純C程序:
#includeint aux[1001]; int a[1001]; void merge(int a[],int l,int mid,int h){ int i=l; int j=mid+1; for(int k=l;k<=h;++k) aux[k]=a[k]; for(int k=l;k<=h;++k){ if(i>mid)a[k]=aux[j++]; else if(j>h)a[k]=aux[i++]; else if(aux[i]
c++版STL:#include#include #include #include #include using namespace std; vector a; int main(int argc, char *argv[]) { int n; int t; while(cin>>n) { a.clear(); for(int i=0;i >t; a.push_back(t); } sort(a.begin(),a.end()); vector ::iterator new_end; new_end=unique(a.begin(),a.end()); cout<<*a.begin(); for(vector ::iterator it=a.begin()+1;it!=new_end;++it) { cout<<" "<<*it; } cout<
高人版(0內存,0ms):#include#include using namespace std; int main() { int n; set st; set ::iterator it; int in; while(cin>>n) { st.clear(); for(int i=0;i >in; st.insert(in); } for(it=st.begin();it!=st.end();it++) { cout<<*it<<" "; } cout<
真有想法~可是set為啥不計入內存呢?OJ問題?沒想明白