Advertisement
Dorreli

Untitled

Jan 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. void fill_in(int* a, const int N, ifstream& file)
  7. {
  8. for (int i = 0; i < N; i++)
  9. {
  10. file >> a[i];
  11. cout << a[i] << " | ";
  12. }
  13. }
  14.  
  15. void coincid(int* a, int* b, int N, int M)
  16. {
  17. int* c;
  18. c = new int[N];
  19. int kk = 0;
  20. cout << endl << "Совпадающие значения: ";
  21. for (int i = 0; i < N; i++)
  22. {
  23. int k_sovp = 0;
  24. for (int j = 0; j < M; j++)
  25. {
  26. if (a[i] == b[j])
  27. {
  28. k_sovp++;
  29. if (k_sovp == 2)
  30. {
  31. if (kk == 0) //встретилось первый раз два раза
  32. {
  33. c[kk] = a[i];
  34. cout << c[kk] << " | ";
  35. kk++;
  36. }
  37. int k_sovp_c = 0;
  38. for (int k = 0; k <= kk; k++)
  39. {
  40. if (c[k] == a[i]) k_sovp_c++;
  41. }
  42. if (k_sovp_c == 0)
  43. {
  44. c[kk] = a[i];
  45. cout << c[kk] << " | ";
  46. kk++;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. cout << endl;
  53. }
  54.  
  55. int main()
  56. {
  57. setlocale(0, "Rus");
  58. ifstream file1("J:\\Универ\\Программирование\\Практика_txt\\z_8_1.txt");
  59. ifstream file2("J:\\Универ\\Программирование\\Практика_txt\\z_8_2.txt");
  60. if ((!file1) && (!file2))
  61. {
  62. cout << "Один или оба файла не открыты" << endl;
  63. system("pause");
  64. return 0;
  65. }
  66. else
  67. {
  68. cout << "Файлы открыты" << endl;
  69. const int N = 10;
  70. int F[N];
  71. cout << "Массив F: " << endl;
  72. fill_in(F, N, file1);
  73. const int M = 40;
  74. int D[M];
  75. cout << endl << "Массив D: " << endl;
  76. fill_in(D, M, file2);
  77. coincid(F, D, N, M);
  78. system("pause");
  79. return 0;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement