fork(4) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. int hash[1001]={0};
  4. int main()
  5. {
  6. //case b>a
  7. //int b[]={1, 3, 2, 8, 7, 1, 9, 3, 6, 8, 8};
  8. //int a[]={2, 1, 1, 3};
  9. //Output : 1 1 3 2
  10.  
  11. //simple case a>b
  12. int a[]={2, 1, 2, 5, 7, 1, 9, 3, 6, 8, 8};
  13. int b[]={2, 1, 8, 3};
  14. //Output : 2 2 1 1 8 8 3 5 7 9 6
  15. int al=sizeof(a)/sizeof(int);
  16. int bl=sizeof(b)/sizeof(int);
  17. int bmax=-1;
  18. int i,j;
  19.  
  20. for(i=0;i<bl;i++){
  21. hash[b[i]]=1;
  22. bmax = bmax>=b[i]?bmax:b[i];
  23. }
  24. for(i=0;i<al;i++){
  25. if(hash[a[i]]>=0) ++hash[a[i]];
  26. }
  27. printf("\nInput \n");
  28. for(i=0;i<al;i++) {printf(" %d ",a[i]);}
  29. printf("\nOrder \n");
  30. for(i=0;i<bl;i++) {printf(" %d ",b[i]);}
  31. printf("\nOutput \n");
  32.  
  33. for(i=0;i<bl;i++){
  34. if(hash[b[i]]>1) {
  35. --hash[b[i]];
  36. while(hash[b[i]]--) printf(" %d ",b[i]);
  37. }
  38. }
  39. for(i=0;i<al;i++) {if(hash[a[i]]>0)printf(" %d ",a[i]);}
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 2296KB
stdin
Standard input is empty
stdout
Input 
 2  1  2  5  7  1  9  3  6  8  8 
Order 
 2  1  8  3 
Output 
 2  2  1  1  8  8  3  5  7  9  6