合并输入的两个整形数组并去掉反复的数字按升序输出;
案例输入:3
1 2 5
4
-1 0 3 2
案例输出:-101
#include<iostream> #include<vector> using namespace std; void maopao(vector<int>&arry); int main() { int N1,N2,num; string line; vector<int>arry1; cin>>N1; for(int i=0;i!=N1;++i) { cin>>num; arry1.push_back(num); } cin>>N2; for(int j=0;j!=N2;++j) { cin>>num; arry1.push_back(num); } maopao(arry1); for(vector<int>::iterator iter=arry1.begin()+1;iter!=arry1.end();++iter) { if(*(iter-1)==*(iter)) { arry1.erase(iter); iter=arry1.begin()+1; } } for(vector<int>::iterator iter2=arry1.begin();iter2!=arry1.end();++iter2) { cout<<*iter2; } cout<<endl; return 0; } void maopao(vector<int>&arry) { int temp; int k; vector<int>::iterator iter; vector<int>::iterator iter1; for(iter=arry.begin(),k=0;iter!=arry.end();++iter,++k) { for(iter1=arry.begin()+1;iter1!=arry.end()-k;++iter1) { if(*(iter1-1)>*iter1) { temp=*(iter1-1); *(iter1-1)=*iter1; *iter1=temp; } } } }
235