Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void Mas(int** mas1, int** mas2, int &n)
- {
- cin >> n;
- *mas1 = new int[n];
- *mas2 = new int[n];
- for (int i = 0; i < n; i++) {
- (*mas1)[i] = rand() % 10;
- }
- for (int j = 0; j < n; j++) {
- (*mas2)[j] = rand() % 10;
- }
- }
- void PrintMas1(int* mas1, int n) {
- for (int i = 0; i < n; i++) {
- cout << mas1[i] << 't';
- }
- cout << endl;
- }
- void PrintMas2( int* mas2, int n){
- for (int j = 0; j < n; j++) {
- cout << mas2[j] << 't';
- }
- cout << endl;
- }
- void Same(int** mas1, int** mas2, int&n) {
- int Sam = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if ((*mas1)[i] == (*mas2)[j]) {
- Sam++;
- }
- }
- }
- int *newMas = new int[Sam];
- int Move = 0;
- for (int i = 0; i < n-Sam; i++) {
- for (int j = 0; j < n-Sam; j++)
- if ((*mas1)[i] == (*mas2)[j]) {
- newMas[Move] = (*mas1)[i];
- Move++;
- }
- }
- for (int i = 0; i < n; i++) {
- cout << newMas[i] << 't';
- }
- cout << endl;
- delete[](newMas);
- }
- int main () {
- int n = 0;
- int *mas1 = NULL;
- int *mas2 = NULL;
- Mas(&mas1, &mas2, n);
- PrintMas1(mas1, n);
- PrintMas2(mas2, n);
- Same(&mas1, &mas2, n);
- delete[] mas1;
- delete[] mas2;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment