Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdio.h>
- using namespace std;
- void fill_in(int* a, const int N, ifstream& file)
- {
- for (int i = 0; i < N; i++)
- {
- file >> a[i];
- cout << a[i] << " | ";
- }
- }
- void coincid(int* a, int* b, int N, int M)
- {
- int* c;
- c = new int[N];
- int kk = 0;
- cout << endl << "Совпадающие значения: ";
- for (int i = 0; i < N; i++)
- {
- int k_sovp = 0;
- for (int j = 0; j < M; j++)
- {
- if (a[i] == b[j])
- {
- k_sovp++;
- if (k_sovp == 2)
- {
- if (kk == 0) //встретилось первый раз два раза
- {
- c[kk] = a[i];
- cout << c[kk] << " | ";
- kk++;
- }
- int k_sovp_c = 0;
- for (int k = 0; k <= kk; k++)
- {
- if (c[k] == a[i]) k_sovp_c++;
- }
- if (k_sovp_c == 0)
- {
- c[kk] = a[i];
- cout << c[kk] << " | ";
- kk++;
- }
- }
- }
- }
- }
- cout << endl;
- }
- int main()
- {
- setlocale(0, "Rus");
- ifstream file1("J:\\Универ\\Программирование\\Практика_txt\\z_8_1.txt");
- ifstream file2("J:\\Универ\\Программирование\\Практика_txt\\z_8_2.txt");
- if ((!file1) && (!file2))
- {
- cout << "Один или оба файла не открыты" << endl;
- system("pause");
- return 0;
- }
- else
- {
- cout << "Файлы открыты" << endl;
- const int N = 10;
- int F[N];
- cout << "Массив F: " << endl;
- fill_in(F, N, file1);
- const int M = 40;
- int D[M];
- cout << endl << "Массив D: " << endl;
- fill_in(D, M, file2);
- coincid(F, D, N, M);
- system("pause");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement