Guest User

Untitled

a guest
Jul 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <iostream.h>
  4.  
  5.  
  6. void main ()
  7. {
  8. clrscr();
  9. int n,m;
  10. float a[100],b[100];
  11. cout<<"Nhap so phan tu cua day a : ";
  12. cin>>n;
  13. cout<<"\nNhap gia tri tung phan tu cua day a :";
  14. for (int i=0;i<n;i++){
  15. cout<<"\n a["<<i+1<<"] = ";
  16. cin>>a[i];
  17. }
  18.  
  19. cout<<"Nhap so phan tu cua day b : ";
  20. cin>>m;
  21. cout<<"\nNhap gia tri tung phan tu cua day b :";
  22. for (int j=0;j<m;j++){
  23. cout<<"\n b["<<j+1<<"] = ";
  24. cin>>b[j];
  25. }
  26.  
  27. // Sap xep day a
  28. int min; float tg;
  29. for(int i=0;i<n-1;i++)
  30. {
  31. min=i;
  32. for(int j=i+1;j<n;j++)
  33. if(a[j]<a[min]) min=j;
  34. tg = a[min]; a[min] = a[i]; a[i] = tg;
  35. }
  36.  
  37. // Sap xep day a
  38. for(int i=0;i<m-1;i++)
  39. {
  40. min=i;
  41. for(int j=i+1;j<m;j++)
  42. if(b[j]<b[min]) min=j;
  43. tg = b[min]; b[min] = b[i]; b[i] = tg;
  44. }
  45.  
  46. cout<<"\nDay a : \n";
  47. for(int i=0;i<n;i++)
  48. cout<<a[i]<<" ";
  49. cout<<"\nDay b : \n";
  50. for(int i=0;i<m;i++)
  51. cout<<b[i]<<" ";
  52.  
  53. // Tron 2 day
  54. int k=0;
  55. for(int i=0;i<n;i++)
  56. {
  57. for(int j=k;j<m;j++)
  58. if(b[j]>a[i])
  59. {
  60. m++;
  61. for(int t=m;t>j;t--)
  62. b[t]=b[t-1];
  63. b[j]=a[i];
  64. k=j;
  65. break;
  66. }
  67. else if ((b[j]<=a[i]) && (j==m-1))
  68. {
  69. for (int t=m;t<m+n-i;t++)
  70. {
  71. b[t]=a[n-i+t-m];
  72. m++;
  73. }
  74. m=m+n-i;
  75. }
  76. }
  77.  
  78. cout<<"\nHai day tron lai : \n";
  79. for(int i=0;i<m;i++)
  80. cout<<b[i]<<" ";
  81.  
  82.  
  83. getch();
  84. }
Add Comment
Please, Sign In to add comment