#include <stdio.h>
#include <string.h>
int hash[1001]={0};
int main()
{
//case b>a
//int b[]={1, 3, 2, 8, 7, 1, 9, 3, 6, 8, 8};
//int a[]={2, 1, 1, 3};
//Output : 1 1 3 2
//simple case a>b
int a[]={2, 1, 2, 5, 7, 1, 9, 3, 6, 8, 8};
int b[]={2, 1, 8, 3};
//Output : 2 2 1 1 8 8 3 5 7 9 6
int al=sizeof(a)/sizeof(int);
int bl=sizeof(b)/sizeof(int);
int bmax=-1;
int i,j;
for(i=0;i<bl;i++){
hash[b[i]]=1;
bmax = bmax>=b[i]?bmax:b[i];
}
for(i=0;i<al;i++){
if(hash[a[i]]>=0) ++hash[a[i]];
}
for(i
=0;i
<al
;i
++) {printf(" %d ",a
[i
]);} for(i
=0;i
<bl
;i
++) {printf(" %d ",b
[i
]);}
for(i=0;i<bl;i++){
if(hash[b[i]]>1) {
--hash[b[i]];
while(hash
[b
[i
]]--) printf(" %d ",b
[i
]); }
}
for(i
=0;i
<al
;i
++) {if(hash
[a
[i
]]>0)printf(" %d ",a
[i
]);}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KaW50IGhhc2hbMTAwMV09ezB9OwppbnQgbWFpbigpCnsKICAgIC8vY2FzZSBiPmEgCiAgICAvL2ludCBiW109ezEsIDMsIDIsIDgsIDcsIDEsIDksIDMsIDYsIDgsIDh9OwogICAgLy9pbnQgYVtdPXsyLCAxLCAxLCAzfTsKICAgIC8vT3V0cHV0IDogMSAgMSAgMyAgMiAKICAgIAogICAgLy9zaW1wbGUgY2FzZSBhPmIKICAgIGludCBhW109ezIsIDEsIDIsIDUsIDcsIDEsIDksIDMsIDYsIDgsIDh9OwogICAgaW50IGJbXT17MiwgMSwgOCwgM307CiAgICAvL091dHB1dCA6IDIgIDIgIDEgIDEgIDggIDggIDMgIDUgIDcgIDkgIDYgCiAgICBpbnQgYWw9c2l6ZW9mKGEpL3NpemVvZihpbnQpOwogICAgaW50IGJsPXNpemVvZihiKS9zaXplb2YoaW50KTsKICAgIGludCBibWF4PS0xOwogICAgaW50IGksajsKICAgIAogICAgZm9yKGk9MDtpPGJsO2krKyl7CiAgICAgICAgaGFzaFtiW2ldXT0xOwogICAgICAgIGJtYXggPSBibWF4Pj1iW2ldP2JtYXg6YltpXTsKICAgIH0KICAgIGZvcihpPTA7aTxhbDtpKyspewogICAgICAgaWYoaGFzaFthW2ldXT49MCkgKytoYXNoW2FbaV1dOwogICAgfQogICAgcHJpbnRmKCJcbklucHV0IFxuIik7CiAgICBmb3IoaT0wO2k8YWw7aSsrKSB7cHJpbnRmKCIgJWQgIixhW2ldKTt9CiAgICBwcmludGYoIlxuT3JkZXIgXG4iKTsKICAgIGZvcihpPTA7aTxibDtpKyspIHtwcmludGYoIiAlZCAiLGJbaV0pO30KICAgIHByaW50ZigiXG5PdXRwdXQgXG4iKTsKICAgIAogICAgZm9yKGk9MDtpPGJsO2krKyl7CiAgICAgICAgaWYoaGFzaFtiW2ldXT4xKSB7CiAgICAgICAgICAgIC0taGFzaFtiW2ldXTsKICAgICAgICAgICAgd2hpbGUoaGFzaFtiW2ldXS0tKSBwcmludGYoIiAlZCAiLGJbaV0pOwogICAgICAgICAgICB9CiAgICB9CiAgICBmb3IoaT0wO2k8YWw7aSsrKSB7aWYoaGFzaFthW2ldXT4wKXByaW50ZigiICVkICIsYVtpXSk7fQogICAgCnJldHVybiAwOwp9Cg==