Guest User

Untitled

a guest
Feb 25th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void Mas(int** mas1, int** mas2, int &n)
  5. {
  6. cin >> n;
  7. *mas1 = new int[n];
  8. *mas2 = new int[n];
  9. for (int i = 0; i < n; i++) {
  10. (*mas1)[i] = rand() % 10;
  11.  
  12. }
  13. for (int j = 0; j < n; j++) {
  14. (*mas2)[j] = rand() % 10;
  15. }
  16. }
  17.  
  18. void PrintMas1(int* mas1, int n) {
  19. for (int i = 0; i < n; i++) {
  20. cout << mas1[i] << 't';
  21. }
  22. cout << endl;
  23. }
  24.  
  25. void PrintMas2( int* mas2, int n){
  26. for (int j = 0; j < n; j++) {
  27. cout << mas2[j] << 't';
  28. }
  29. cout << endl;
  30. }
  31.  
  32. void Same(int** mas1, int** mas2, int&n) {
  33. int Sam = 0;
  34. for (int i = 0; i < n; i++) {
  35. for (int j = 0; j < n; j++) {
  36. if ((*mas1)[i] == (*mas2)[j]) {
  37. Sam++;
  38. }
  39. }
  40. }
  41. int *newMas = new int[Sam];
  42. int Move = 0;
  43. for (int i = 0; i < n-Sam; i++) {
  44. for (int j = 0; j < n-Sam; j++)
  45. if ((*mas1)[i] == (*mas2)[j]) {
  46. newMas[Move] = (*mas1)[i];
  47. Move++;
  48. }
  49. }
  50. for (int i = 0; i < n; i++) {
  51. cout << newMas[i] << 't';
  52. }
  53. cout << endl;
  54. delete[](newMas);
  55.  
  56. }
  57.  
  58.  
  59.  
  60. int main () {
  61. int n = 0;
  62. int *mas1 = NULL;
  63. int *mas2 = NULL;
  64. Mas(&mas1, &mas2, n);
  65. PrintMas1(mas1, n);
  66. PrintMas2(mas2, n);
  67. Same(&mas1, &mas2, n);
  68. delete[] mas1;
  69. delete[] mas2;
  70. system("pause");
  71. return 0;
  72. }
Add Comment
Please, Sign In to add comment