Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <iostream.h>
- void main ()
- {
- clrscr();
- int n,m;
- float a[100],b[100];
- cout<<"Nhap so phan tu cua day a : ";
- cin>>n;
- cout<<"\nNhap gia tri tung phan tu cua day a :";
- for (int i=0;i<n;i++){
- cout<<"\n a["<<i+1<<"] = ";
- cin>>a[i];
- }
- cout<<"Nhap so phan tu cua day b : ";
- cin>>m;
- cout<<"\nNhap gia tri tung phan tu cua day b :";
- for (int j=0;j<m;j++){
- cout<<"\n b["<<j+1<<"] = ";
- cin>>b[j];
- }
- // Sap xep day a
- int min; float tg;
- for(int i=0;i<n-1;i++)
- {
- min=i;
- for(int j=i+1;j<n;j++)
- if(a[j]<a[min]) min=j;
- tg = a[min]; a[min] = a[i]; a[i] = tg;
- }
- // Sap xep day a
- for(int i=0;i<m-1;i++)
- {
- min=i;
- for(int j=i+1;j<m;j++)
- if(b[j]<b[min]) min=j;
- tg = b[min]; b[min] = b[i]; b[i] = tg;
- }
- cout<<"\nDay a : \n";
- for(int i=0;i<n;i++)
- cout<<a[i]<<" ";
- cout<<"\nDay b : \n";
- for(int i=0;i<m;i++)
- cout<<b[i]<<" ";
- // Tron 2 day
- int k=0;
- for(int i=0;i<n;i++)
- {
- for(int j=k;j<m;j++)
- if(b[j]>a[i])
- {
- m++;
- for(int t=m;t>j;t--)
- b[t]=b[t-1];
- b[j]=a[i];
- k=j;
- break;
- }
- else if ((b[j]<=a[i]) && (j==m-1))
- {
- for (int t=m;t<m+n-i;t++)
- {
- b[t]=a[n-i+t-m];
- m++;
- }
- m=m+n-i;
- }
- }
- cout<<"\nHai day tron lai : \n";
- for(int i=0;i<m;i++)
- cout<<b[i]<<" ";
- getch();
- }
Add Comment
Please, Sign In to add comment