7-51代码:(map)
#include<iostream>
#include<map>
using namespace std;
map<int,int>mp;
int cnt,cnttp;
void scan(){
while(1){
int x; scanf("%d",&x);
if(x==-1) break;
mp[x]++;cnt++;
}
}
int main(){
scan();scan();
if(!mp.size()) printf("NULL");
for(auto it=mp.begin();it!=mp.end();it++){
while(it->second--){
cnttp++;
if(cnttp==cnt) printf("%d",it->first);
else printf("%d ",it->first);
}
}
return 0;
}
7-52代码:(map+vector)
#include<iostream>
#include<map>
#include<vector>
using namespace std;
map<int,int>mp;
vector<int>vc;
int main(){
while(1){
int x; scanf("%d",&x);
if(x==-1) break;
mp[x]++;
}
while(1){
int x; scanf("%d",&x);
if(x==-1) break;
if(mp[x]){
mp[x]--;
vc.push_back(x);
}
}
if(!vc.size()) printf("NULL");
else{
for(int i=0;i<vc.size()-1;i++)
printf("%d ",vc[i]);
printf("%d",vc[vc.size()-1]);
}
return 0;
}