Advertisement
huutho_96

xoa trung

Mar 25th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void nhapmang(int a[], int m, int b[], int n)
  4. {
  5. for (int i = 0; i < m; i++)
  6. {
  7. cout << "nhap phan tu thu " << i + 1 << ": ";
  8. cin >> a[i];
  9. }
  10. for (int i = 0; i < n; i++)
  11. {
  12. cout << "nhap phan tu thu " << i + 1 << ": ";
  13. cin >> b[i];
  14. }
  15. }
  16. void xuatmang(int a[], int n)
  17. {
  18. for (int i = 0; i < n; i++)
  19. {
  20. cout << "phan tu thu " << i + 1 << ": " << a[i] << endl;
  21. }
  22. }
  23. void xoa(int a[], int k, int &n)
  24. {
  25. for (int i = k; i < n - 1; i++)
  26. a[i] = a[i + 1];
  27. n--;
  28. }
  29. void xoagiatrik(int a[], int k, int &n)
  30. {
  31. for (int i = 0; i < n; i++)
  32. {
  33. if (a[i] == k) xoa(a, i, n);
  34. }
  35. }
  36. void xoatrung(int a[], int &n, int b[], int &m)
  37. {
  38. int i, j, k = 0, m1 = m;
  39. for (i = 0; i < n; i++)
  40. {
  41. k = a[i];
  42. xoagiatrik(b, k, m);
  43. if (m1 > m)
  44. {
  45. xoagiatrik(a, k, n);
  46. m1 = m;
  47. i--;
  48. }
  49. }
  50. }
  51. void main()
  52. {
  53. int a[10], b[15], n = 5, m = 7;
  54. nhapmang(a, n, b, m);
  55. xoatrung(a, n, b, m);
  56. cout << "mang 1\n";
  57. xuatmang(a, n);
  58. cout << "mang 2\n";
  59. xuatmang(b, m);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement