fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int* shift(int a,int b[],int size)
  5. {
  6. for (int i = 0; i+1 < size; i++)
  7. b[i+1] = b[i];
  8.  
  9. return b;
  10. }
  11.  
  12. int main() {
  13. // your code goes here
  14. int m,n;
  15. cin>>n>>m;
  16. //DYNAMIC ARRAY DECLARATION
  17. int *a=NULL;
  18. int *b=NULL;
  19. a=new int[n];
  20. b=new int[m+n];
  21.  
  22. //Taking elements into array n
  23. for (int i=0;i<n;i++)
  24. {
  25. cin>>a[i];
  26. // cout<<a[i]<<" ";
  27. }
  28. for(int i=0;i<m+n;i++)
  29. {
  30. cin>>b[i];
  31. //cout<<b[i]<<" ";
  32. }
  33. for(int i=0;i<n;i++)
  34. {
  35. for (int j=0;j<m+n;j++)
  36. {
  37. if(a[0]<b[0])
  38. {
  39. int p=j;
  40. shift(0,b,m+n);
  41. //while((p+1)<m+n)
  42. //b[p+1]=b[p];
  43.  
  44. b[0]=a[0];
  45. }
  46. if (a[i]<=b[j] && a[i]>=b[j-1])
  47. {
  48. int q;
  49. q=j;
  50. shift(j,b,m+n);
  51. //while((q+1)<m+n)
  52. //b[q+1]=b[q];
  53.  
  54. b[j]=a[i];
  55. }
  56. }
  57. }
  58. for (int i=0;i<m+n;i++)
  59. {
  60. cout<<b[i];
  61. }
  62. return 0;
  63. }
Success #stdin #stdout 0s 15240KB
stdin
4
5
1 4 5 7
2 3 6 8 10
stdout
111111111